2019-11-05 21:18:20 +00:00
|
|
|
from model.example import Example
|
|
|
|
from model.translation import Translation
|
2019-11-13 22:20:34 +00:00
|
|
|
from model.editable import Editable
|
2019-11-05 21:18:20 +00:00
|
|
|
|
2019-11-11 22:04:45 +00:00
|
|
|
|
2019-11-13 22:20:34 +00:00
|
|
|
class Sense(Editable):
|
2019-11-05 21:18:20 +00:00
|
|
|
def __init__(self, sense_xml):
|
|
|
|
definition = sense_xml.querySelector("definitionList definition")
|
|
|
|
|
2019-11-11 23:34:52 +00:00
|
|
|
self.labels = [label.textContent for label in sense_xml.querySelectorAll("labelList label")]
|
2019-11-05 21:18:20 +00:00
|
|
|
self.definition = definition.textContent if definition else ""
|
|
|
|
|
|
|
|
self.examples = [Example(example_xml) for example_xml in
|
|
|
|
sense_xml.querySelectorAll("exampleContainerList exampleContainer")]
|
|
|
|
|
|
|
|
translations = []
|
|
|
|
max_num_cluster = 0
|
|
|
|
|
|
|
|
for translation_xml in sense_xml.querySelectorAll("translationContainerList translationContainer"):
|
|
|
|
num_cluster = int(translation_xml.getAttribute("cluster"))
|
|
|
|
max_num_cluster = max(max_num_cluster, num_cluster)
|
|
|
|
translations.append((num_cluster, Translation(translation_xml)))
|
|
|
|
|
|
|
|
self.translations = [[] for _ in range(max_num_cluster)]
|
|
|
|
for clusterNum, translation in translations:
|
|
|
|
self.translations[clusterNum - 1].append(translation)
|
|
|
|
|
2019-11-15 21:24:32 +00:00
|
|
|
|
|
|
|
class NewSense(Sense):
|
|
|
|
def __init__(self):
|
|
|
|
self.translations = []
|
|
|
|
self.labels = []
|
|
|
|
self.definition = []
|
|
|
|
self.examples= []
|