Sha256: c7d8c1f9a34f5de30fe0e6727bae82c20cda9b4cface7fb0538e984b3b246566
Contents?: true
Size: 818 Bytes
Versions: 4
Compression:
Stored size: 818 Bytes
Contents
$KCODE = 'UTF8' def process(path, tree) File.open(path, 'r') do |file| file.each_line do |line| node = nil line.chars.each do |c| next if c == "\n" || c == "\r" if node node[c] ||= {} node = node[c] else tree[c] ||= Hash.new node = tree[c] end end node[:end] = true end end end def build tree = {} dictionaries = ['cedict.zh_CN.utf8', 'wikipedia.zh.utf8'] dictionaries.each do |dictionary| puts "Processing #{dictionary}..." path = File.join(File.dirname(__FILE__), '../../dict', dictionary) process(path, tree) end File.open(hash_path, "wb") {|io| Marshal.dump(tree, io)} puts 'Done' end def hash_path File.join(File.dirname(__FILE__), '../../dict/dict.hash') end build
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
rseg-0.1.7 | lib/builder/dict.rb |
rseg-0.1.6 | lib/builder/dict.rb |
rseg-0.1.5 | lib/builder/dict.rb |
rseg-0.1.4 | lib/builder/dict.rb |