py/gadict_c5.py
changeset 394 4d45194c71b6
parent 393 2756a6deca7e
child 399 a6a7036f3c6f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/py/gadict_c5.py	Sun Mar 27 16:49:11 2016 +0300
@@ -0,0 +1,59 @@
+
+import gadict
+import io
+import sys
+
+
+fgadict = None
+fnout = None
+if len(sys.argv) >= 2:
+    fgadict = sys.argv[1]
+if len(sys.argv) >= 3:
+    fnout = sys.argv[2]
+
+fin = io.open(fgadict, mode='r', buffering=1, encoding="utf-8")
+if fnout is None:
+    fout = sys.stdout
+else:
+    fout = open(fnout, "w")
+
+
+parser = gadict.Parser()
+dom = parser.parse(fin)
+fin.close()
+
+for idx in range(1, len(dom)):
+    article = dom[idx]
+    fout.write("_____\n\n")
+    title = "; ".join(article[0].keys())
+    fout.write(title)
+    fout.write("\n\n")
+    for (word, (pron, attrs)) in article[0].items():
+        if word == "approach":
+            fout.write(str(article[0]))
+        fout.write("  ")
+        fout.write(word)
+        fout.write("\n")
+        if pron is not None:
+            fout.write("    [")
+            fout.write(pron)
+            fout.write("]\n")
+        if len(attrs) > 0:
+            fout.write("    ")
+            l = list(attrs)
+            l.sort()
+            fout.write(", ".join(l))
+            fout.write("\n")
+    fout.write("\n")
+    for (pos, trs, exs) in article[1]:
+        fout.write("  ")
+        if pos is not None:
+            fout.write("⟨")
+            fout.write(pos)
+            fout.write("⟩ ")
+        for (lang, tr) in trs:
+            if lang == "ru":
+                fout.write(tr)
+                break
+        fout.write("\n")
+