example translations and sense translation now unified, should behave very simmilary
- import - export - view - edite translation events
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from model.editable import Editable
|
||||
from model.translation import from_container_list
|
||||
|
||||
class Example(Editable):
|
||||
def __init__(self, example_xml):
|
||||
@@ -15,7 +16,4 @@ class Example(Editable):
|
||||
|
||||
self.original_xml = inner_xml
|
||||
self.text = inner_xml.textContent
|
||||
|
||||
self.translations = []
|
||||
for translation in example_xml.querySelectorAll("translationContainer translation"):
|
||||
self.translations.append(translation.textContent)
|
||||
self.translations = from_container_list(example_xml.querySelectorAll("translationContainer"))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from model.example import Example
|
||||
from model.translation import Translation
|
||||
from model.translation import from_container_list
|
||||
from model.editable import Editable
|
||||
from model.tags import import_label_list
|
||||
|
||||
@@ -15,18 +15,8 @@ class Sense(Editable):
|
||||
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)
|
||||
|
||||
self.translations = from_container_list(
|
||||
sense_xml.querySelectorAll("translationContainerList translationContainer"))
|
||||
|
||||
def merge_labels(self):
|
||||
return ", ".join(val for _, val in self.labels)
|
||||
|
||||
@@ -2,6 +2,25 @@ from model.tags import import_label_list
|
||||
from model.editable import Editable
|
||||
|
||||
|
||||
def from_container_list(translation_list_container_xml):
|
||||
translations = []
|
||||
max_num_cluster = 0
|
||||
|
||||
for translation_xml in translation_list_container_xml:
|
||||
num_cluster = 1 # default cluster
|
||||
if translation_xml.hasAttribute("cluster"):
|
||||
num_cluster = int(translation_xml.getAttribute("cluster"))
|
||||
|
||||
max_num_cluster = max(max_num_cluster, num_cluster)
|
||||
translations.append((num_cluster, Translation(translation_xml)))
|
||||
|
||||
result = [[] for _ in range(max_num_cluster)]
|
||||
for clusterNum, translation in translations:
|
||||
result[clusterNum - 1].append(translation)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
class Translation(Editable):
|
||||
def __init__(self, translation_xml):
|
||||
translation = translation_xml.querySelector("translation")
|
||||
|
||||
Reference in New Issue
Block a user