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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
#!/usr/bin/python2
# convert Dalj-like dictionary into .tei format
# http://enrus.antex.ru/home/indexe.html
# dictionary consists of lines, each line is one entry and looks like this:
# WORD definition
#or
# WORD, definition
def tran(input, output, s):
r = ''
for c in s:
i = string.find(input, c)
if i >= 0: c = output[i]
r = r+c
return r
def low(s):
return tran('', 'ţ', s)
import sys, string
f = open(sys.argv[1], "r")
pos = 0
lastlinepos = 0
inword = 0
word = ""
def teiheader():
print """<!DOCTYPE TEI.2 PUBLIC "-//TEI P3//DTD Main Document Type//EN" [
<!ENTITY % TEI.dictionaries "INCLUDE" >
]>
<tei.2>
<teiHeader>
<filedesc>
<titlestmt>
<title> </title>
</titlestmt>
<publicationstmt>
<authority>Freedict.de</authority>
</publicationstmt>
<sourcedesc>
<p>http://enrus.antex.ru/home/indexe.html</p>
</sourcedesc>
</filedesc>
</teiHeader>
"""
words = {}
block = ""
teiheader()
print "<text>"
print "<body>"
while 1:
#i = readblock(f) # or f.readline
i = f.readline()
if not i:
break
endpos = pos+len(i)
i = string.strip(i)
i = string.replace(i, '\n', '')
seppos = 0
while 1:
if i[seppos] in (" ", ","):
word, definition = i[:seppos], i[seppos+1:]
break
seppos = seppos+1
one = word
one = low(one)
definition = string.replace(definition, '<', '<')
definition = string.replace(definition, '>', '>')
definition = string.replace(definition, ' /| ', ' | ')
definition = string.replace(definition, ' |/ ', ' | ')
dl = string.split(definition, " | ")
two = dl
if words.has_key(one):
words[one].extend(two)
else:
words[one] = two
for i, j in words.items():
print "<entry>"
print " <form>"
print " <orth>"+i+"</orth>"
print " </form>"
print " <trans>"
for k in j:
print " <tr>"+k+"</tr>"
print " </trans>"
print "</entry>"
print "</body>"
print "</text>"
print "</tei.2>"
|