py/gadict.py
changeset 565 ac68f2680ea0
parent 554 59714b9033bc
child 566 0bba61492c37
--- a/py/gadict.py	Sat Sep 17 10:18:12 2016 +0300
+++ b/py/gadict.py	Wed Sep 21 22:09:37 2016 +0300
@@ -45,7 +45,7 @@
 
 class Sense:
 
-    def __init__(self, pos, tr_list = None, ex_list = None, syn_list = None, ant_list = None, topic_list = None):
+    def __init__(self, pos, tr_list = None, ex_list = None, ant_list = None, syn_list = None, rel_list = None, topic_list = None):
         if not pos:
             raise ParseException("Part of speech expected...\n")
         self.pos = pos
@@ -53,36 +53,43 @@
         if not tr_list:
             self.tr_list = []
         self.ex_list = ex_list
+        self.ant_list = ant_list
         self.syn_list = syn_list
-        self.ant_list = ant_list
+        self.rel_list = rel_list
         self.topic_list = topic_list
 
     def add_tr(self, tr):
         self.tr_list.append(tr)
 
     def add_ex(self, ex):
-        if not self.ex_list:
+        if self.ex_list:
+            self.ex_list.append(ex)
+        else:
             self.ex_list = [ex]
+
+    def add_ant(self, ant):
+        if self.ant_list:
+            self.ant_list.append(ant)
         else:
-            self.ex_list.append(ex)
+            self.ant_list = [ant]
 
     def add_syn(self, syn):
-        if not self.syn_list:
+        if self.syn_list:
+            self.syn_list.append(syn)
+        else:
             self.syn_list = [syn]
-        else:
-            self.syn_list.append(syn)
 
-    def add_ant(self, ant):
-        if not self.ant_list:
-            self.ant_list = [ant]
+    def add_rel(self, rel):
+        if self.rel_list:
+            self.rel_list.append(rel)
         else:
-            self.ant_list.append(ant)
+            self.rel_list = [rel]
 
     def add_topic(self, topic):
-        if not self.topic_list:
+        if self.topic_list:
+            self.topic_list.append(topic)
+        else:
             self.topic_list = [topic]
-        else:
-            self.topic_list.append(topic)
 
     def __str__(self):
         if tr_list:
@@ -107,6 +114,7 @@
     TOPIC_RE = regex.compile(u"^topic: (\\p{L}.*)$")
     SYN_RE = regex.compile(u"^syn: (\\p{L}.*)$")
     ANT_RE = regex.compile(u"^ant: (\\p{L}.*)$")
+    REL_RE = regex.compile(u"^rel: (\\p{L}.*)$")
 
     CONT_RE = regex.compile(u"^ +(.*)")
 
@@ -314,6 +322,15 @@
                         raise ParseException("""Empty antonym...""")
                     sense.add_ant(ant)
                 continue
+            m = self.REL_RE.match(self.line)
+            if m is not None:
+                rels = m.group(1).split(";")
+                for rel in rels:
+                    rel = rel.strip()
+                    if len(rel) == 0:
+                        raise ParseException("""Empty relation...""")
+                    sense.add_rel(rel)
+                continue
             m = self.TRANSL_RE.match(self.line)
             if m is not None:
                 sense.add_tr((m.group(1), m.group(2) + self.parse_translation_continuation()))