--- a/py/gadict.py Sun Jan 21 16:44:25 2018 +0200
+++ b/py/gadict.py Wed Jan 31 00:26:12 2018 +0200
@@ -47,7 +47,7 @@
class Sense:
- def __init__(self, pos, tr_list = None, ex_list = None, glos_list = None, ant_list = None, syn_list = None, rel_list = None, topic_list = None, hyper_list = None, hypo_list = None, col_list = None):
+ def __init__(self, pos, tr_list = None, ex_list = None, glos_list = None, ant_list = None, syn_list = None, rel_list = None, topic_list = None, hyper_list = None, hypo_list = None, col_list = None, countable = None):
if not pos:
raise ParseException("Part of speech expected...\n")
self.pos = pos
@@ -61,6 +61,7 @@
self.hyper_list = hyper_list
self.hypo_list = hypo_list
self.col_list = col_list
+ self.countable = countable
def add_tr(self, tr):
if self.tr_list:
@@ -122,6 +123,19 @@
else:
self.col_list = [col]
+ def set_countable(self, countable):
+ if isinstance(countable, str):
+ if countable == 'yes':
+ self.countable = True
+ elif countable == 'no':
+ self.countable = False
+ else:
+ raise ParseException("Countable can only be yes/no.")
+ elif isinstance(countable, bool):
+ self.countable = countable
+ else:
+ raise ParseException("Countable can only be yes/no or bool.")
+
def __str__(self):
if tr_list:
(lang, text) = self.tr_list[0]
@@ -144,6 +158,7 @@
TRANSL_RE = re.compile(u"^(ru|uk|la|en): ([\\w(].*)$", re.UNICODE)
TRANSL_EX_RE = re.compile(u"""^(ru|uk|la|en)> ([-'"\\w].*)$""", re.UNICODE)
TRANSL_GLOS_RE = re.compile(u"^(ru|uk|la|en)= ([-\\w\\d].*)$", re.UNICODE)
+ CNT_RE = re.compile(u"^cnt: (yes|no)$", re.UNICODE)
TOPIC_RE = re.compile(u"^topic: (\\w.*)$", re.UNICODE)
SYN_RE = re.compile(u"^syn: (\\w.*)$", re.UNICODE)
ANT_RE = re.compile(u"^ant: (\\w.*)$", re.UNICODE)
@@ -342,6 +357,10 @@
continue
if not sense:
raise ParseException("""Missing part of speech marker...""")
+ m = self.CNT_RE.match(self.line)
+ if m is not None:
+ sense.set_countable(m.group(1))
+ continue
m = self.TOPIC_RE.match(self.line)
if m is not None:
topics = m.group(1).split(";")