equal
deleted
inserted
replaced
1 |
1 |
2 import io |
|
3 import sys |
|
4 # import re |
|
5 import regex |
2 import regex |
6 |
|
7 |
|
8 # fgadict = "gadict_en-ru+ua.gadict" |
|
9 fgadict = None |
|
10 fnout = None |
|
11 if len(sys.argv) >= 2: |
|
12 fgadict = sys.argv[1] |
|
13 if len(sys.argv) >= 3: |
|
14 fnout = sys.argv[2] |
|
15 |
|
16 fin = io.open(fgadict, mode='r', buffering=1, encoding="utf-8") |
|
17 if fnout is None: |
|
18 fout = sys.stdout |
|
19 else: |
|
20 fout = open(fnout, "w") |
|
21 |
3 |
22 |
4 |
23 class ParseException(Exception): |
5 class ParseException(Exception): |
24 |
6 |
25 def __init__(self, msg): |
7 def __init__(self, msg): |
161 raise ParseException("""Uknown syntax...""") |
143 raise ParseException("""Uknown syntax...""") |
162 if len(tr) > 0: |
144 if len(tr) > 0: |
163 senses.append((pos, tr, ex)) |
145 senses.append((pos, tr, ex)) |
164 self.tran = senses |
146 self.tran = senses |
165 |
147 |
166 parser = Parser() |
|
167 dom = parser.parse(fin) |
|
168 fin.close() |
|
169 |
|
170 for idx in range(1, len(dom)): |
|
171 article = dom[idx] |
|
172 fout.write("_____\n\n") |
|
173 title = "; ".join(article[0].keys()) |
|
174 fout.write(title) |
|
175 fout.write("\n\n") |
|
176 for (word, (pron, attrs)) in article[0].items(): |
|
177 if word == "approach": |
|
178 fout.write(str(article[0])) |
|
179 fout.write(" ") |
|
180 fout.write(word) |
|
181 fout.write("\n") |
|
182 if pron is not None: |
|
183 fout.write(" [") |
|
184 fout.write(pron) |
|
185 fout.write("]\n") |
|
186 if len(attrs) > 0: |
|
187 fout.write(" ") |
|
188 l = list(attrs) |
|
189 l.sort() |
|
190 fout.write(", ".join(l)) |
|
191 fout.write("\n") |
|
192 fout.write("\n") |
|
193 for (pos, trs, exs) in article[1]: |
|
194 fout.write(" ") |
|
195 if pos is not None: |
|
196 fout.write("⟨") |
|
197 fout.write(pos) |
|
198 fout.write("⟩ ") |
|
199 for (lang, tr) in trs: |
|
200 if lang == "ru": |
|
201 fout.write(tr) |
|
202 break |
|
203 fout.write("\n") |
|
204 |
|
205 # fout.write(str(article[0])+"\n") |
|
206 |
|