class Natural::Synonym

Public Class Methods

find(options) click to toggle source
Calls superclass method Natural::Fragment::find
# File lib/natural/fragment.rb, line 297
def self.find(options)
  super options.merge(:looking_for => options[:synonyms].values.flatten)
end

Public Instance Methods

replacements(options) click to toggle source
# File lib/natural/fragment.rb, line 300
def replacements(options)
  options[:synonyms].values.each do |alternatives|
    if alternatives.include?(self.to_s.singularize.downcase)
      return (alternatives - [self.to_s]).map do |alternative_text|
        if self.node_height == 0
          alternative_text = alternative_text.pluralize if self.to_s.plural?
          alternative = self.class.new(:ids => self.ids, :text => alternative_text)
          alternative << Fragment.new(:ids => (alternative.ids.first..alternative.ids.last).to_a, :text => options[:text].split(' ')[alternative.ids.first..alternative.ids.last].join(' '))
          alternative
        else
          return [self]
        end
      end
    end
  end
end