File: migemo-cache.rb

package info (click to toggle)
migemo 0.32-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 3,764 kB
  • ctags: 123
  • sloc: ruby: 971; sh: 541; makefile: 113
file content (27 lines) | stat: -rw-r--r-- 605 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require 'migemo'
$KCODE="e"
raise if ARGV[0] == nil
dict = ARGV[0]
static_dict = MigemoStaticDict.new(dict)
ARGV.shift

cache  = File.new(dict + ".cache", "w")
index  = File.new(dict + ".cache.idx", "w")

idx = 0
lines = readlines.sort
lines.each do |line|
  pattern = line.chomp!
  $stderr.puts pattern
  next if pattern == ""

  migemo = Migemo.new(static_dict, pattern)
  migemo.optimization = 3
  data = Marshal.dump(migemo.regex_tree)
  output = [pattern.length].pack("N") + pattern + 
    [data.length].pack("N") + data
  cache.print output
  index.print [idx].pack("N")
  idx += output.length
end