module Dawg::Finder
Public Instance Methods
get_childs(node)
click to toggle source
# File lib/dawg/finder.rb, line 38 def get_childs(node) Enumerator.new do |result| node.each_edge do |letter| next_node = node[letter] next if next_node.nil? get_childs(next_node).each do |s| result << Word.new(letter) + s end result << Word.new(letter, next_node.final) end end end
lookup(word)
click to toggle source
# File lib/dawg/finder.rb, line 7 def lookup(word) node = @the_node word.each_char do |letter| next_node = node[letter] return false if next_node.nil? node = next_node end node.final end
query(word)
click to toggle source
get all words with given prefix
# File lib/dawg/finder.rb, line 19 def query(word) node = @the_node word.split('').each do |letter| next_node = node[letter] return [] if next_node.nil? node = next_node end Enumerator.new do |result| result << Word.new(word, node.final).to_s if node.final get_childs(node).each do |s| current_word = (Word.new(word) + s) result << current_word.to_s if current_word.final end end end
set_the_node(node)
click to toggle source
# File lib/dawg/finder.rb, line 3 def set_the_node(node) @the_node = node end