Meanings.py
1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#! /usr/bin/python
# -*- coding: utf-8 -*-
class Meaning:
def __init__(self, id, name, variant):
self._id = id
self._name = name
self._variant = variant
@classmethod
def fromTree(cls, meaning_tree):
id = meaning_tree._attrs['xml:id']
name = meaning_tree._children[0]._children[0]._content
variant = meaning_tree._children[1]._children[0]._content
return cls(id, name, variant)
def getId(self):
return self._id
def __unicode__(self):
return '\'' + self._name + '\'-' + self._variant
class Meanings:
def __init__(self, meanings):
self._meanings = meanings
@classmethod
def fromTree(cls, meanings_tree):
meanings = {}
for subtree in meanings_tree._children[0]._children[0]._children:
meaning = Meaning.fromTree(subtree)
meanings[meaning.getId()] = meaning
return cls(meanings)
def getMeanings(self):
return self.meanings
def __unicode__(self):
return '[' + ','.join([unicode(meaning) for meaning in self._meanings.values()]) + ']'