py/gadict.py
changeset 554 59714b9033bc
parent 553 45a3138c9b4d
child 565 ac68f2680ea0
--- a/py/gadict.py	Thu Sep 15 15:42:52 2016 +0300
+++ b/py/gadict.py	Thu Sep 15 17:48:20 2016 +0300
@@ -31,6 +31,18 @@
         else:
             return ":{:d}: {:s}\nLINE: {:s}".format(self.lineno, self.msg.encode('utf-8'), self.line.encode('utf-8'))
 
+class Headword:
+
+    def __init__(self, headword, pron = None, attrs = None):
+        self.headword = headword
+        self.pron = pron
+        self.attrs = attrs
+
+    def __str__(self):
+        return self.headword
+    def __repr__(self):
+        return "<Headword {}>".format(self.headword)
+
 class Sense:
 
     def __init__(self, pos, tr_list = None, ex_list = None, syn_list = None, ant_list = None, topic_list = None):
@@ -72,6 +84,14 @@
         else:
             self.topic_list.append(topic)
 
+    def __str__(self):
+        if tr_list:
+            (lang, text) = self.tr_list[0]
+            return "{}: {}".format(lang, text)
+        return "<empy sence>"
+    def __repr__(self):
+        return "<Sence {}>".format(str(self))
+
 class Parser:
     """gadict dictionary format parser."""
 
@@ -190,7 +210,7 @@
 
     def parse_headlines(self):
         """Try to match word variations with attributed. Assume that `self.line` on preceding empty line."""
-        self.words = {}
+        self.words = []
         self.readline()
         if self.eof:
             raise ParseException("""There are no definition after "__" delimiter...""")
@@ -208,7 +228,7 @@
             if m is not None:
                 if word is None:
                     raise ParseException("""Didn't match previous headword...""")
-                self.words[word] = (pron, attrs)
+                self.words.append(Headword(word, pron, attrs))
                 word = m.group(1)
                 pron = None
                 attrs = set()
@@ -224,7 +244,7 @@
                 attrs.add(m.group(1))
                 continue
             raise ParseException("""Line is not a headword or translation or headword attribute...""")
-        self.words[word] = (pron, attrs)
+        self.words.append(Headword(word, pron, attrs))
 
     def parse_translation_continuation(self):
         string = ""