class Natural::Spelling

Public Class Methods

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

Public Instance Methods

replacements(options) click to toggle source
# File lib/natural/fragment.rb, line 278
def replacements(options)
  options[:spellings].each do |canonical, alternatives|
    if alternatives.include?(self.to_s.singularize.downcase)
      return [canonical].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
          [self]
        end
      end
    end
  end
end