Class: DidYouMean::TreeSpellChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/did_you_mean/tree_spell_checker.rb

Overview

spell checker for a dictionary that has a tree structure, see doc/tree_spell_checker_api.md

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dictionary:, separator: '/', augment: nil) ⇒ TreeSpellChecker

Returns a new instance of TreeSpellChecker.



7
8
9
10
11
12
# File 'lib/did_you_mean/tree_spell_checker.rb', line 7

def initialize(dictionary:, separator: '/', augment: nil)
  @dictionary = dictionary
  @separator = separator
  @augment = augment
  @dimensions = parse_dimensions
end

Instance Attribute Details

#augmentObject (readonly)

Returns the value of attribute augment.



5
6
7
# File 'lib/did_you_mean/tree_spell_checker.rb', line 5

def augment
  @augment
end

#dictionaryObject (readonly)

Returns the value of attribute dictionary.



5
6
7
# File 'lib/did_you_mean/tree_spell_checker.rb', line 5

def dictionary
  @dictionary
end

#dimensionsObject (readonly)

Returns the value of attribute dimensions.



5
6
7
# File 'lib/did_you_mean/tree_spell_checker.rb', line 5

def dimensions
  @dimensions
end

#separatorObject (readonly)

Returns the value of attribute separator.



5
6
7
# File 'lib/did_you_mean/tree_spell_checker.rb', line 5

def separator
  @separator
end

Instance Method Details

#correct(input) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/did_you_mean/tree_spell_checker.rb', line 14

def correct(input)
  plausibles = plausible_dimensions input
  return no_idea(input) if plausibles.empty?
  suggestions = find_suggestions input, plausibles
  return no_idea(input) if suggestions.empty?
  suggestions
end