Commit a401d6a2 authored by Neeme Kahusk's avatar Neeme Kahusk
Browse files

Lisatud __str__ Variandile

parent e099d1b1
......@@ -3,6 +3,34 @@
"""
This is the new eurown module.
>>> import eurown
>>> a = eurown.Synset(43)
>>> b = eurown.Variant('loom',1)
>>> c = eurown.Variant('elajas',2)
>>> a.add_variant(b)
>>> print(a)
0 @43-n@ WORD_MEANING
1 PART_OF_SPEECH "n"
1 VARIANTS
2 LITERAL "loom"
3 SENSE 1
>>> print(b)
2 LITERAL "loom"
3 SENSE 1
>>> print(c)
2 LITERAL "elajas"
3 SENSE 2
>>> a.add_variant(c)
>>> print(a)
0 @43-n@ WORD_MEANING
1 PART_OF_SPEECH "n"
1 VARIANTS
2 LITERAL "loom"
3 SENSE 1
2 LITERAL "elajas"
3 SENSE 2
"""
def format_polaris(level, field, value=None,
......@@ -40,21 +68,54 @@ class Synset:
self.internal_links = internal_links
self.eq_links = eq_links
self.property_values = property_values
if not id:
self.id = '{}-{}'.format(1, self.pos)
if id:
self.id = '{}-{}'.format(id, self.pos)
else:
self.id = ''
def add_variant(self, variant):
self.variants.append(variant)
def __str__(self):
if self.id:
out = format_polaris(0, 'WORD_MEANING', None, self.id)
else:
out = format_polaris(0, 'WORD_MEANING')
if self.pos: # should always be true
out = '{}\n{}'.format(out,
format_polaris(1,
'PART_OF_SPEECH',
self.pos)
)
if self.variants:
out = '{}\n{}'.format(out,
format_polaris(1,
'VARIANTS')
)
out = '{}\n{}'.format(out,
'\n'.join([str(i) for i in self.variants])
)
# def __str__(self):
return out
class Variant:
def __init__(self, lemma, sense,
gloss, examples):
gloss=None, examples=[]):
self.lemma = lemma
self.sense = sense
self.gloss = gloss
self.examples = examples
def __str__(self):
out = format_polaris(2, 'LITERAL', self.lemma)
out = '{}\n{}'.format(out,
format_polaris(3, 'SENSE', self.sense,
None, False)
)
return out
class InternalLink:
def __init__(self, name=None):
self.name = name
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment