Class: Natural::Expansion

Inherits:
Alternative show all
Defined in:
lib/natural/fragment.rb

Instance Attribute Summary

Attributes inherited from Fragment

#aggregator, #filter, #score, #text

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Alternative

#score

Methods inherited from Fragment

#all_filters, #clone, #data, #id_range, #ids, #ids=, #initialize, #pretty_to_s, recurse_alternatives, #to_s

Constructor Details

This class inherits a constructor from Natural::Fragment

Class Method Details

.find(options) ⇒ Object



319
320
321
# File 'lib/natural/fragment.rb', line 319

def self.find(options)
  super options.merge(:looking_for => options[:expansions].keys)
end

Instance Method Details

#replacements(options) ⇒ Object



322
323
324
325
326
327
328
329
330
331
332
333
334
# 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