Class: Natural::Spelling
- Inherits:
-
Alternative
- Object
- Tree::TreeNode
- Fragment
- Alternative
- Natural::Spelling
- 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
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
275 276 277 |
# File 'lib/natural/fragment.rb', line 275 def self.find() super .merge(:looking_for => [:spellings].values.flatten) end |
Instance Method Details
#replacements(options) ⇒ Object
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/natural/fragment.rb', line 278 def replacements() [: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 => [:text].split(' ')[alternative.ids.first..alternative.ids.last].join(' ')) alternative else [self] end end end end end |