Split generator from parser.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Sun, 27 Mar 2016 16:49:11 +0300
changeset 394 4d45194c71b6
parent 393 2756a6deca7e
child 395 32309860fe92
Split generator from parser.
py/gadict.py
py/gadict_c5.py
--- a/py/gadict.py	Sun Mar 27 16:44:14 2016 +0300
+++ b/py/gadict.py	Sun Mar 27 16:49:11 2016 +0300
@@ -1,25 +1,7 @@
 
-import io
-import sys
-# import re
 import regex
 
 
-# fgadict = "gadict_en-ru+ua.gadict"
-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")
-
-
 class ParseException(Exception):
 
     def __init__(self, msg):
@@ -163,44 +145,3 @@
             senses.append((pos, tr, ex))
         self.tran = senses
 
-parser = 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")
-
-    # fout.write(str(article[0])+"\n")
-
--- /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")
+