Order irregular verbs, noun plural form and adverb/adjective comparison form
authorOleksandr Gavenko <gavenkoa@gmail.com>
Sat, 27 Aug 2016 14:37:58 +0300
changeset 537 a70ab6a33bfa
parent 536 c9f0064d8661
child 538 163fc28bff2d
Order irregular verbs, noun plural form and adverb/adjective comparison form in headword list.
py/gadict_c5.py
--- a/py/gadict_c5.py	Sat Aug 27 14:32:25 2016 +0300
+++ b/py/gadict_c5.py	Sat Aug 27 14:37:58 2016 +0300
@@ -64,13 +64,39 @@
 FOUT.write(PRELUDE.about)
 FOUT.write("\n")
 
+
+def attr_key(item):
+    (word, (pron, attrs)) = item
+    if not attrs:
+        return "zzz"
+    best_vattr = None
+    for attr in attrs:
+        if attr in ["v1", "v2", "v3"]:
+            if not best_vattr or (best_vattr and best_vattr > attr):
+                best_vattr = attr
+    if best_vattr:
+        return best_vattr
+    for attr in attrs:                      # single/plural
+        if attr in ["s"]:
+            return attr
+    for attr in attrs:                      # comparative/superlative
+        if attr in ["comp"]:
+            return attr
+    for attr in attrs:                      # Am/Br/Au
+        if attr in ["Am"]:
+            return attr
+    return "zzz"
+
+
 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():
+    defs = article[0].items()
+    defs = sorted(defs, key = attr_key)
+    for (word, (pron, attrs)) in defs:
         FOUT.write("  ")
         FOUT.write(word)
         if pron is not None: