Sha256: e798e1970fbd67e67557069d4cb02c2f4aeee639b9b3ce60ee455a10ead2308a
Contents?: true
Size: 829 Bytes
Versions: 2
Compression:
Stored size: 829 Bytes
Contents
class Dict < Engine @@root = nil @@dict_path = File.join(File.dirname(__FILE__), '../../dict/dict.hash') class << self def dict_path=(path) @@dict_path = path end def dict_path @@dict_path end end def initialize @@root ||= load_dict(@@dict_path) @word = '' @node = @@root super end def process(char) match = false word = nil if @node[char] @word << char @node = @node[char] match = true else if @node[:end] || @word.chars.to_a.length == 1 word = @word else word = @word.chars.to_a end @node = @@root @word = '' match = false end [match, word] end private def load_dict(path) File.open(path, "rb") {|io| Marshal.load(io)} end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rseg-0.1.5 | lib/engines/dict.rb |
rseg-0.1.4 | lib/engines/dict.rb |