Commit 0c05548f authored by Neeme Kahusk's avatar Neeme Kahusk
Browse files

Synset.variants=None

parent 8d1c0388
......@@ -10,7 +10,7 @@ This is the new eurown module.
>>> c = eurown.Variant('elajas',2)
>>> a.add_variant(b)
>>> print(a)
0 @43-n@ WORD_MEANING
0 @43@ WORD_MEANING
1 PART_OF_SPEECH "n"
1 VARIANTS
2 LITERAL "loom"
......@@ -23,7 +23,7 @@ This is the new eurown module.
3 SENSE 2
>>> a.add_variant(c)
>>> print(a)
0 @43-n@ WORD_MEANING
0 @43@ WORD_MEANING
1 PART_OF_SPEECH "n"
1 VARIANTS
2 LITERAL "loom"
......@@ -33,7 +33,7 @@ This is the new eurown module.
>>> a.variants[0].gloss = "elusorganism, mida tavaliselt iseloomustab \
vabatahtliku liikumise võime ja närvisüsteemi olemasolu"
>>> print(a)
0 @43-n@ WORD_MEANING
0 @43@ WORD_MEANING
1 PART_OF_SPEECH "n"
1 VARIANTS
2 LITERAL "loom"
......@@ -70,9 +70,8 @@ def format_polaris(level, field, value=None,
return out
class Synset:
ids = []
def __init__(self, id='', pos='n', variants=[],
class Synset(object):
def __init__(self, number='', pos='n', variants=None,
internal_links=[], eq_links=[],
property_values=[]):
self.pos = pos
......@@ -80,25 +79,36 @@ class Synset:
self.internal_links = internal_links
self.eq_links = eq_links
self.property_values = property_values
if id:
self.id = '{}-{}'.format(id, self.pos)
else:
self.id = ''
self.number = number
# if id:
# self.id = '{}-{}'.format(id, self.pos)
# else:
# self.id = ''
self.fieldname = 'WORD_MEANING'
def add_variant(self, variant):
if not self.variants:
self.variants = []
self.variants.append(variant)
def add_internal_link(self, internal_link):
self.internal_links.append(internal_link)
def add_eq_link(self, eq_link):
self.eq_links.append(eq_link)
def __str__(self):
if self.id:
out = format_polaris(0, 'WORD_MEANING', None, self.id)
if self.number:
out = format_polaris(0, self.fieldname, None, self.number)
else:
out = format_polaris(0, 'WORD_MEANING')
out = format_polaris(0, self.fieldname)
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,
......@@ -107,6 +117,22 @@ class Synset:
out = '{}\n{}'.format(out,
'\n'.join([str(i) for i in self.variants])
)
if self.internal_links:
out = '{}\n{}'.format(out,
format_polaris(1,
'INTERNAL_LINKS')
)
out = '{}\n{}'.format(out,
'\n'.join([str(i) for i in self.internal_links])
)
if self.eq_links:
out = '{}\n{}'.format(out,
format_polaris(1,
'EQ_LINKS')
)
out = '{}\n{}'.format(out,
'\n'.join([str(i) for i in self.eq_links])
)
return out
......@@ -152,11 +178,14 @@ class Variant:
return out
class InternalLink:
def __init__(self, name=None):
def __init__(self, name, target_concept,
features=[]):
self.name = name
self.target_concept = target_concept
self.features = features
if __name__ == '__main__':
print(format_polaris(0, 'WORD_MEANING', record=222))
# print(format_polaris(0, 'WORD_MEANING', record=222))
import doctest
doctest.testmod()
%% Cell type:markdown id: tags:
# Eurown testing
%% Cell type:code id: tags:
``` python
>>> import eurown
>>> a = eurown.Synset(43)
>>> b = eurown.Variant('loom',1)
>>> c = eurown.Variant('elajas',2)
>>> a.add_variant(b)
>>> print(a)
```
%% Cell type:code id: tags:
``` python
>>> print(b)
```
%% Cell type:code id: tags:
``` python
>>> print(c)
```
%% Cell type:code id: tags:
``` python
>>> a.add_variant(c)
>>> print(a)
```
%% Cell type:code id: tags:
``` python
>>> a.variants[0].gloss = "elusorganism, mida tavaliselt iseloomustab \
vabatahtliku liikumise võime ja närvisüsteemi olemasolu"
>>> print(a)
```
%% Cell type:code id: tags:
``` python
d = eurown.Synset(44)
print(d)
```
%% Cell type:code id: tags:
``` python
d.add_variant(eurown.Variant('elusolend',1))
d.add_variant(eurown.Variant('organism',2))
d.variants[0].gloss = 'elusorganism, hrl. inimene v. loom'
print(d)
```
%% Cell type:code id: tags:
``` python
snset = eurown.Synset()
print(snset)
```
%% Cell type:code id: tags:
``` python
```
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