equal
deleted
inserted
replaced
|
1 |
|
2 import gadict |
|
3 import io |
|
4 import sys |
|
5 |
|
6 |
|
7 fgadict = None |
|
8 fnout = None |
|
9 if len(sys.argv) >= 2: |
|
10 fgadict = sys.argv[1] |
|
11 if len(sys.argv) >= 3: |
|
12 fnout = sys.argv[2] |
|
13 |
|
14 fin = io.open(fgadict, mode='r', buffering=1, encoding="utf-8") |
|
15 if fnout is None: |
|
16 fout = sys.stdout |
|
17 else: |
|
18 fout = open(fnout, "w") |
|
19 |
|
20 |
|
21 parser = gadict.Parser() |
|
22 dom = parser.parse(fin) |
|
23 fin.close() |
|
24 |
|
25 for idx in range(1, len(dom)): |
|
26 article = dom[idx] |
|
27 fout.write("_____\n\n") |
|
28 title = "; ".join(article[0].keys()) |
|
29 fout.write(title) |
|
30 fout.write("\n\n") |
|
31 for (word, (pron, attrs)) in article[0].items(): |
|
32 if word == "approach": |
|
33 fout.write(str(article[0])) |
|
34 fout.write(" ") |
|
35 fout.write(word) |
|
36 fout.write("\n") |
|
37 if pron is not None: |
|
38 fout.write(" [") |
|
39 fout.write(pron) |
|
40 fout.write("]\n") |
|
41 if len(attrs) > 0: |
|
42 fout.write(" ") |
|
43 l = list(attrs) |
|
44 l.sort() |
|
45 fout.write(", ".join(l)) |
|
46 fout.write("\n") |
|
47 fout.write("\n") |
|
48 for (pos, trs, exs) in article[1]: |
|
49 fout.write(" ") |
|
50 if pos is not None: |
|
51 fout.write("⟨") |
|
52 fout.write(pos) |
|
53 fout.write("⟩ ") |
|
54 for (lang, tr) in trs: |
|
55 if lang == "ru": |
|
56 fout.write(tr) |
|
57 break |
|
58 fout.write("\n") |
|
59 |