class Natural::Expansion

Public Class Methods

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

Public Instance Methods

replacements(options) click to toggle source
# File lib/natural/fragment.rb, line 322
def replacements(options)
  alternatives = options[:expansions][self.to_s.singularize.downcase] || []
  return alternatives.map do |alternative_text|
    alternative_text = alternative_text.pluralize if self.to_s.plural?
    if self.node_height == 0
      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