spell checker for a dictionary that has a tree structure, see doc/tree_spell_checker_api.md
Methods
- C
-
- D
-
- F
-
- N
-
- P
-
- T
-
Attributes
[R]
|
augment |
|
[R]
|
dictionary |
|
[R]
|
separator |
|
Class Public methods
new(dictionary:, separator: '/', augment: nil)
Link
Source:
show
| on GitHub
def initialize(dictionary:, separator: '/', augment: nil)
@dictionary = dictionary
@separator = separator
@augment = augment
end
Instance Public methods
correct(input)
Link
Source:
show
| on GitHub
def correct(input)
plausibles = plausible_dimensions(input)
return fall_back_to_normal_spell_check(input) if plausibles.empty?
suggestions = find_suggestions(input, plausibles)
return fall_back_to_normal_spell_check(input) if suggestions.empty?
suggestions
end
dictionary_without_leaves()
Link
Source:
show
| on GitHub
def dictionary_without_leaves
@dictionary_without_leaves ||= dictionary.map { |word| word.split(separator)[0..-2] }.uniq
end
dimensions()
Link
Source:
show
| on GitHub
def dimensions
@dimensions ||= tree_depth.times.map do |index|
dictionary_without_leaves.map { |element| element[index] }.compact.uniq
end
end
find_leaves(path)
Link
Source:
show
| on GitHub
def find_leaves(path)
path_with_separator = "#{path}#{separator}"
dictionary
.select {|str| str.include?(path_with_separator) }
.map {|str| str.gsub(path_with_separator, '') }
end
plausible_dimensions(input)
Link
Source:
show
| on GitHub
def plausible_dimensions(input)
input.split(separator)[0..-2]
.map
.with_index { |element, index| correct_element(dimensions[index], element) if dimensions[index] }
.compact
end
possible_paths(states)
Link
Source:
show
| on GitHub
def possible_paths(states)
states.map { |state| state.join(separator) }
end
tree_depth()
Link
Source:
show
| on GitHub
def tree_depth
@tree_depth ||= dictionary_without_leaves.max { |a, b| a.size <=> b.size }.size
end