|
Revision 1, 0.6 kB
(checked in by mjoc, 2 years ago)
|
Initial import.
|
| Line | |
|---|
| 1 |
#!/usr/bin/env python |
|---|
| 2 |
|
|---|
| 3 |
# MakeHash |
|---|
| 4 |
# Utility for dictionary hash table making |
|---|
| 5 |
# mjoc, 2003 |
|---|
| 6 |
|
|---|
| 7 |
import sys |
|---|
| 8 |
|
|---|
| 9 |
if len(sys.argv) < 3: |
|---|
| 10 |
print "Usage: %s <dict_file> <hash_file>" % sys.argv[0] |
|---|
| 11 |
sys.exit(1) |
|---|
| 12 |
|
|---|
| 13 |
fdDict = open(sys.argv[1]) |
|---|
| 14 |
fdHash = open(sys.argv[2], "w") |
|---|
| 15 |
|
|---|
| 16 |
print "Indexing..." |
|---|
| 17 |
|
|---|
| 18 |
hash = {} |
|---|
| 19 |
|
|---|
| 20 |
line = fdDict.readline() |
|---|
| 21 |
l = line[0:2].lower() |
|---|
| 22 |
n = 0 |
|---|
| 23 |
|
|---|
| 24 |
hash[l] = n |
|---|
| 25 |
n += len(line) |
|---|
| 26 |
|
|---|
| 27 |
for line in fdDict.readlines(): |
|---|
| 28 |
l = line[0:2].lower() |
|---|
| 29 |
if not hash.has_key(l): |
|---|
| 30 |
hash[l] = n |
|---|
| 31 |
n += len(line) |
|---|
| 32 |
|
|---|
| 33 |
for l, p in hash.items(): |
|---|
| 34 |
fdHash.write("%s %s\n" % (l, p)) |
|---|
| 35 |
|
|---|
| 36 |
fdDict.close() |
|---|
| 37 |
fdHash.close() |
|---|
| 38 |
|
|---|