File: conv.py

package info (click to toggle)
dict-moby-thesaurus 1.0-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 25,852 kB
  • ctags: 8
  • sloc: makefile: 51; python: 29; sh: 25
file content (35 lines) | stat: -rw-r--r-- 1,004 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
28
29
30
31
32
33
34
35
import sys, dictdlib

# Conversion script by John Goerzen

itextfile = open("introduction.txt", "rt")


dw = dictdlib.DictWriter("moby-thesaurus",
                         'http://www.ibiblio.org/pub/docs/books/gutenberg/etext02/mthes10.zip',
                         'Moby Thesaurus II by Grady Ward, 1.0',
                         itextfile.read(-1))

while 1:
    line = sys.stdin.readline()
    if not line:
        break
    line.strip()
    base, d = line.split(',', 1)
    defstr = ""
    defline = "   "
    count = 0
    for defword in d.split(','):
        count += 1
        if len(defline) + len(defword) + 3 > 70:
            defstr += defline + "," + "\n"
            defline = "   " + defword
        elif defline == "   ":
            defline += defword
        else:
            defline += ", " + defword
    if defline != "   ":
        defstr += defline + "\n"
    dw.writeentry("%s Moby Thesaurus words for \"%s\":\n" % (count, base) + \
                  defstr, [base])
dw.finish()