Sha256: d4ffc8b8f2f0c37b1099239a7eb23c41c319d2390f49b2fbb2545df325626333
Contents?: true
Size: 833 Bytes
Versions: 1
Compression:
Stored size: 833 Bytes
Contents
#coding: utf-8 $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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rseg1.9-0.1.5 | lib/builder/dict.rb |