changeset 566 | 0bba61492c37 |
parent 565 | ac68f2680ea0 |
child 568 | 4b610eaaf4be |
565:ac68f2680ea0 | 566:0bba61492c37 |
---|---|
43 def __repr__(self): |
43 def __repr__(self): |
44 return "<Headword {}>".format(self.headword) |
44 return "<Headword {}>".format(self.headword) |
45 |
45 |
46 class Sense: |
46 class Sense: |
47 |
47 |
48 def __init__(self, pos, tr_list = None, ex_list = None, ant_list = None, syn_list = None, rel_list = None, topic_list = None): |
48 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): |
49 if not pos: |
49 if not pos: |
50 raise ParseException("Part of speech expected...\n") |
50 raise ParseException("Part of speech expected...\n") |
51 self.pos = pos |
51 self.pos = pos |
52 self.tr_list = tr_list |
52 self.tr_list = tr_list |
53 if not tr_list: |
53 if not tr_list: |
54 self.tr_list = [] |
54 self.tr_list = [] |
55 self.ex_list = ex_list |
55 self.ex_list = ex_list |
56 self.glos_list = glos_list |
|
56 self.ant_list = ant_list |
57 self.ant_list = ant_list |
57 self.syn_list = syn_list |
58 self.syn_list = syn_list |
58 self.rel_list = rel_list |
59 self.rel_list = rel_list |
59 self.topic_list = topic_list |
60 self.topic_list = topic_list |
60 |
61 |
64 def add_ex(self, ex): |
65 def add_ex(self, ex): |
65 if self.ex_list: |
66 if self.ex_list: |
66 self.ex_list.append(ex) |
67 self.ex_list.append(ex) |
67 else: |
68 else: |
68 self.ex_list = [ex] |
69 self.ex_list = [ex] |
70 |
|
71 def add_glos(self, glos): |
|
72 if self.glos_list: |
|
73 self.glos_list.append(glos) |
|
74 else: |
|
75 self.glos_list = [glos] |
|
69 |
76 |
70 def add_ant(self, ant): |
77 def add_ant(self, ant): |
71 if self.ant_list: |
78 if self.ant_list: |
72 self.ant_list.append(ant) |
79 self.ant_list.append(ant) |
73 else: |
80 else: |
109 HEADWORD_VAR_RE = regex.compile(u"^ +(s|pl|v[123]|male|female|comp|super|abbr|Am|Br|Au)$") |
116 HEADWORD_VAR_RE = regex.compile(u"^ +(s|pl|v[123]|male|female|comp|super|abbr|Am|Br|Au)$") |
110 HEADWORD_PRON_RE = regex.compile(u"^ +\\[([\p{L}' ]+)\\]$") |
117 HEADWORD_PRON_RE = regex.compile(u"^ +\\[([\p{L}' ]+)\\]$") |
111 TRANSL_POS_RE = regex.compile(u"^n|det|pron|adj|v|adv|prep|conj|num|int|phr|phr\\.v|contr|abbr|prefix$") |
118 TRANSL_POS_RE = regex.compile(u"^n|det|pron|adj|v|adv|prep|conj|num|int|phr|phr\\.v|contr|abbr|prefix$") |
112 TRANSL_RE = regex.compile(u"^(ru|uk|la|en): ([\\p{L}(].*)$") |
119 TRANSL_RE = regex.compile(u"^(ru|uk|la|en): ([\\p{L}(].*)$") |
113 TRANSL_EX_RE = regex.compile(u"^(ru|uk|la|en)> ([-\\p{L}].*)$") |
120 TRANSL_EX_RE = regex.compile(u"^(ru|uk|la|en)> ([-\\p{L}].*)$") |
121 TRANSL_GLOS_RE = regex.compile(u"^(ru|uk|la|en)= ([-\\p{L}].*)$") |
|
114 TOPIC_RE = regex.compile(u"^topic: (\\p{L}.*)$") |
122 TOPIC_RE = regex.compile(u"^topic: (\\p{L}.*)$") |
115 SYN_RE = regex.compile(u"^syn: (\\p{L}.*)$") |
123 SYN_RE = regex.compile(u"^syn: (\\p{L}.*)$") |
116 ANT_RE = regex.compile(u"^ant: (\\p{L}.*)$") |
124 ANT_RE = regex.compile(u"^ant: (\\p{L}.*)$") |
117 REL_RE = regex.compile(u"^rel: (\\p{L}.*)$") |
125 REL_RE = regex.compile(u"^rel: (\\p{L}.*)$") |
118 |
126 |
339 m = self.TRANSL_EX_RE.match(self.line) |
347 m = self.TRANSL_EX_RE.match(self.line) |
340 if m is not None: |
348 if m is not None: |
341 sense.add_ex((m.group(1), m.group(2) + self.parse_translation_continuation())) |
349 sense.add_ex((m.group(1), m.group(2) + self.parse_translation_continuation())) |
342 read = False |
350 read = False |
343 continue |
351 continue |
352 m = self.TRANSL_GLOS_RE.match(self.line) |
|
353 if m is not None: |
|
354 sense.add_glos((m.group(1), m.group(2) + self.parse_translation_continuation())) |
|
355 read = False |
|
356 continue |
|
344 raise ParseException("""Uknown syntax...""") |
357 raise ParseException("""Uknown syntax...""") |
345 self.tran = senses |
358 self.tran = senses |