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

paindlikum faiilist lugeja

parent 73101d67
......@@ -80,6 +80,18 @@ def find_parent(current, level, theList):
else:
return i
def read_variants(first, iterator):
a = first
if (a['level'],a['field']) == (2, 'LITERAL'):
v = Variant(a['value'])
while a['level'] < 2:
if (a['level'],a['field']) == (3, 'SENSE'):
v.sense = a['value']
elif (a['level'],a['field']) == (3, 'DEFINITION'):
v.gloss = a['value']
a = next(iterator, None)
return v
class Lexicon:
......@@ -176,63 +188,10 @@ class Synset(object):
if a['field'] == 'VARIANTS':
a = next(iterator, None)
while a['level'] > 1:
if (a['level'],a['field']) == (2,'LITERAL'):
literal = a['value']
elif (a['level'],a['field']) == (3,'SENSE'):
sense = a['value']
self.add_variant(Variant(literal,sense))
elif (a['level'],a['field']) == (3,'DEFINITION'):
self.variants[-1].gloss = a['value']
elif (a['level'],a['field']) == (3,'EXAMPLES'):
a = next(iterator, None)
while a['level'] > 3:
self.variants[-1].add_example(Example(a['value']))
a = next(iterator, None)
if (a['level'],a['field']) == (3,'EXTERNAL_INFO'):
a = next(iterator, None)
while a['level'] > 3:
if (a['level'],a['field']) == (4,'SOURCE_ID'):
source_id = a['value']
self.variants[-1].add_external_info(
ExternalInfo(source_id))
elif (a['level'],a['field']) == (5,'TEXT_KEY'):
tk = a['value']
self.variants[
-1].external_info[-1].text_key = tk
a = next(iterator, None)
a = next(iterator, None)
if a['field'] == 'INTERNAL_LINKS':
a = next(iterator, None)
while a['level'] > 1:
if (a['level'],a['field']) == (2,'RELATION'):
name = a['value']
elif (a['level'],a['field']) == (3,'TARGET_CONCEPT'):
il = InternalLink(name, Synset())
elif (a['level'],a['field']) == (4,'PART_OF_SPEECH'):
il.target_concept.pos = a['value']
elif (a['level'],a['field']) == (4,'LITERAL'):
literal = a['value']
elif (a['level'],a['field']) == (5,'SENSE'):
sense = a['value']
il.target_concept.add_variant(Variant(literal, sense))
self.add_internal_link(il)
a = next(iterator, None)
if a['field'] == 'EQ_LINKS':
a = next(iterator, None)
while a and a['level'] > 1:
if (a['level'],a['field']) == (2,'EQ_RELATION'):
name = a['value']
elif (a['level'],a['field']) == (3,'TARGET_ILI'):
il = EqLink(name, Synset())
elif (a['level'],a['field']) == (4,'PART_OF_SPEECH'):
il.target_concept.pos = a['value']
# elif (a['level'],a['field']) == (4,'LITERAL'):
# literal = a['value']
elif (a['level'],a['field']) == (4,'WORDNET_OFFSET'):
sense = a['value']
il.target_concept.wordnet_offset = sense
self.add_eq_link(il)
a = next(iterator, None)
self.add_variant(read_variants(a, iterator))
return self
def __str__(self):
......@@ -287,7 +246,7 @@ class Instance(Synset):
class Variant:
def __init__(self, lemma, sense,
def __init__(self, lemma=None, sense=None,
gloss=None, examples=None,
external_info=None):
self.lemma = lemma
......@@ -302,6 +261,19 @@ class Variant:
def add_external_info(self, external_info):
self.external_info.append(external_info)
# def read(self, iterator):
# a = next(iterator, None)
# print(a)
# out = '{} {}'.format('loen varianti',a)
# if (a['level'],a['field']) == (2,'LITERAL'):
# self.lemma = a['value']
# a = next(iterator, None)
# while a['level'] > 2:
# if (a['level'],a['field']) == (3,'SENSE'):
# self.sense = a['value']
# a = next(iterator, None)
# return self
def __str__(self):
out = format_polaris(2, 'LITERAL', self.lemma)
out = '{}\n{}'.format(out,
......@@ -418,18 +390,18 @@ if __name__ == '__main__':
'est', '01')
lex.read_file()
# a = Synset()
# a.lexicon = lex
# a.read(2)
# print(a)
a = Synset()
a.lexicon = lex
a.read(2)
print(a)
snset_indexes = [[j,i] for j,i in enumerate(lex.data) if 'level' in i and i['level'] == 0]
# print(len(snset_indexes))
# print(snset_indexes[:5])
# snset_indexes = [[j,i] for j,i in enumerate(lex.data) if 'level' in i and i['level'] == 0]
# # print(len(snset_indexes))
# # print(snset_indexes[:5])
snsets = [Synset(lexicon=lex).read(0) for i in snset_indexes]
# snsets = [Synset(lexicon=lex).read(0) for i in snset_indexes]
# print(snsets)
# # print(snsets)
for i in snsets:
print(i)
# for i in snsets:
# print(i)
Markdown is supported
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