Object
![show/hide quicksearch [+]](../images/find.png)
spell checker for a dictionary that has a tree structure, see doc/tree_spell_checker_api.md
 
               # File did_you_mean/tree_spell_checker.rb, line 15
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
             
             
               # File did_you_mean/tree_spell_checker.rb, line 25
def dictionary_without_leaves
  @dictionary_without_leaves ||= dictionary.map { |word| word.split(separator)[0..-2] }.uniq
end
             
             
               # File did_you_mean/tree_spell_checker.rb, line 33
def dimensions
  @dimensions ||= tree_depth.times.map do |index|
                    dictionary_without_leaves.map { |element| element[index] }.compact.uniq
                  end
end
             
             
               # File did_you_mean/tree_spell_checker.rb, line 39
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
             
             
               # File did_you_mean/tree_spell_checker.rb, line 47
def plausible_dimensions(input)
  input.split(separator)[0..-2]
    .map
    .with_index { |element, index| correct_element(dimensions[index], element) if dimensions[index] }
    .compact
end