Sha256: c29a06a0108a8169b8e537cf541b361653724c9152e79946fec742411e6df936

Contents?: true

Size: 820 Bytes

Versions: 5

Compression:

Stored size: 820 Bytes

Contents

# encoding: utf-8

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

5 entries across 5 versions & 3 rubygems

Version Path
rseg_harry-0.0.4 lib/builder/dict.rb
rseg_harry-0.0.3 lib/builder/dict.rb
rseg_ggharry-0.0.2 lib/builder/dict.rb
rseg_ggharry-0.0.1 lib/builder/dict.rb
rseg-ggharry-0.0.1 lib/builder/dict.rb