translationContainerList implementation

This commit is contained in:
matic_t 2020-08-12 06:18:00 -07:00
parent 48c51c38de
commit 8049f5ed95
4 changed files with 39 additions and 39 deletions

View File

@ -141,7 +141,9 @@ def export_sense(doc, sense):
for example in sense.examples: for example in sense.examples:
example_container = example.export(doc) example_container = example.export(doc)
export_translation_list(doc, example, example_container) translation_container_list = doc.createElement("translationContainerList")
export_translation_list(doc, example, translation_container_list)
example_container.appendChild(translation_container_list)
example_container_list.appendChild(example_container) example_container_list.appendChild(example_container)
return sense_xml return sense_xml

View File

@ -18,12 +18,12 @@ class Example(Data):
self.components = [] self.components = []
self.edited = False self.edited = False
self.newly_created = False self.newly_created = False
# removes space from last component if multiword example # removes space from last component if multiword example
def check_multiword_components(self): def check_multiword_components(self):
if self.is_multiword(): if self.is_multiword():
self.components[len(self.components) - 1].no_space = ComponentLexeme.LAST_COMPONENT_SPACE self.components[len(self.components) - 1].no_space = ComponentLexeme.LAST_COMPONENT_SPACE
@staticmethod @staticmethod
def new_multiword(): def new_multiword():
example = Example() example = Example()
@ -32,105 +32,105 @@ class Example(Data):
example.inner = MultiwordExample() example.inner = MultiwordExample()
example.inner.cluster = ExampleClusters.first_empty_cluster() example.inner.cluster = ExampleClusters.first_empty_cluster()
example.inner.type = "grammaticalCombination" example.inner.type = "grammaticalCombination"
empty_component = ComponentLexeme() empty_component = ComponentLexeme()
empty_component.role = "headword" empty_component.role = "headword"
example.components.append(empty_component) example.components.append(empty_component)
return example return example
def import_xml(self, example_xml): def import_xml(self, example_xml):
self.translations = from_container_list(example_xml.querySelectorAll("translationContainer")) self.translations = from_container_list(example_xml.querySelectorAll("translationContainerList translationContainer"))
if example_xml.hasAttribute("modified"): if example_xml.hasAttribute("modified"):
self.edited = example_xml.getAttribute("modified") == "true" self.edited = example_xml.getAttribute("modified") == "true"
inner_xml = example_xml.querySelector("corpusExample") inner_xml = example_xml.querySelector("corpusExample")
if inner_xml is not None: if inner_xml is not None:
self.inner = CorpusExample() self.inner = CorpusExample()
else: else:
inner_xml = example_xml.querySelector("multiwordExample") inner_xml = example_xml.querySelector("multiwordExample")
self.inner = MultiwordExample() self.inner = MultiwordExample()
self.inner.import_xml(inner_xml) self.inner.import_xml(inner_xml)
for idx, comp_xml in enumerate(inner_xml.childNodes): for idx, comp_xml in enumerate(inner_xml.childNodes):
comp = ComponentLexeme() comp = ComponentLexeme()
comp.import_xml(comp_xml) comp.import_xml(comp_xml)
if comp.isValid(): if comp.isValid():
self.components.append(comp) self.components.append(comp)
self.check_multiword_components() self.check_multiword_components()
def export(self, doc): def export(self, doc):
self.check_multiword_components() self.check_multiword_components()
result = doc.createElement("exampleContainer") result = doc.createElement("exampleContainer")
inner = self.inner.export(doc, self.edited) inner = self.inner.export(doc, self.edited)
# TODO: bad quick fix # TODO: bad quick fix
for comp in self.components: for comp in self.components:
inner.appendChild(comp.export(doc)) inner.appendChild(comp.export(doc))
result.appendChild(inner) result.appendChild(inner)
return result return result
def view(self, model, sense): def view(self, model, sense):
example_tag = "div.example-rest" example_tag = "div.example-rest"
if self in model.chosen_examples: if self in model.chosen_examples:
example_tag += ".example-chosen" example_tag += ".example-chosen"
cluster = self.get_cluster() cluster = self.get_cluster()
dot_attr = {"style": { "visibility": "visible" if cluster is None else "hidden"}} dot_attr = {"style": { "visibility": "visible" if cluster is None else "hidden"}}
example_content = [] example_content = []
if cluster is not None: if cluster is not None:
example_content.append(h("span.example-cluster", {}, str(cluster + 1))) example_content.append(h("span.example-cluster", {}, str(cluster + 1)))
example_text_inner_tag = "span.example-text-{}".format(self.get_view_type()) example_text_inner_tag = "span.example-text-{}".format(self.get_view_type())
example_content.append(h(example_text_inner_tag, {}, self.inner.view(self.components))) example_content.append(h(example_text_inner_tag, {}, self.inner.view(self.components)))
other_attributes = self.get_other_attributes() other_attributes = self.get_other_attributes()
if "frequency" in other_attributes: if "frequency" in other_attributes:
example_content.append(h("span.example-frequency", {}, other_attributes["frequency"])) example_content.append(h("span.example-frequency", {}, other_attributes["frequency"]))
if "logDice" in other_attributes: if "logDice" in other_attributes:
example_content.append(h("span.example-logdice", {}, other_attributes["logDice"])) example_content.append(h("span.example-logdice", {}, other_attributes["logDice"]))
parent_display = "none" parent_display = "none"
if model.examples_shown or self.is_multiword() or len(self.translations) > 0: if model.examples_shown or self.is_multiword() or len(self.translations) > 0:
parent_display = "inherit" parent_display = "inherit"
clusters_display = "inherit" clusters_display = "inherit"
if not model.clusters_shown: if not model.clusters_shown:
clusters_display = "none" clusters_display = "none"
return h("div.example", {"style": {"display": parent_display}}, [ return h("div.example", {"style": {"display": parent_display}}, [
h("div.example-dot", dot_attr, ""), h("div.example-dot", dot_attr, ""),
h(example_tag, {}, [ h(example_tag, {}, [
h("span.example-text", {"on": {"click": M.msg(M.ShowExampleMenu, self)} }, example_content), h("span.example-text", {"on": {"click": M.msg(M.ShowExampleMenu, self)} }, example_content),
h("div.example-translation-list", {}, [ h("div.example-translation-list", {}, [
h("div.example-translation", {}, View.view_translations(self.translations, self, model))]), h("div.example-translation", {}, View.view_translations(self.translations, self, model))]),
h("div.example-clusters", h("div.example-clusters",
{"style": {"display": clusters_display }}, show_toggle_cluster_buttons(sense, self))])]) {"style": {"display": clusters_display }}, show_toggle_cluster_buttons(sense, self))])])
def simple_view(self): def simple_view(self):
return self.inner.view(self.components) return self.inner.view(self.components)
def get_cluster(self): def get_cluster(self):
return self.inner.get_cluster() return self.inner.get_cluster()
def set_cluster(self, cluster): def set_cluster(self, cluster):
self.inner.cluster = cluster self.inner.cluster = cluster
def get_structure(self): def get_structure(self):
return self.inner.get_structure() return self.inner.get_structure()
def is_collocation(self): def is_collocation(self):
return self.get_view_type() == 2 return self.get_view_type() == 2
def is_multiword(self): def is_multiword(self):
return self.get_view_type() != 1 return self.get_view_type() != 1
def get_view_type(self): def get_view_type(self):
# as per the bosses, these are the rules for different colors # as per the bosses, these are the rules for different colors
if type(self.inner) is CorpusExample: if type(self.inner) is CorpusExample:
@ -139,8 +139,8 @@ class Example(Data):
return 2 return 2
else: else:
return 3 return 3
def get_other_attributes(self): def get_other_attributes(self):
return self.inner.other_attributes return self.inner.other_attributes

View File

@ -25,7 +25,7 @@ class Sense(Data):
self.labels = import_label_list("sense > labelList label", sense_xml) self.labels = import_label_list("sense > labelList label", sense_xml)
self.translations = from_container_list( self.translations = from_container_list(
sense_xml.querySelectorAll("translationContainerList translationContainer")) sense_xml.querySelectorAll('sense > translationContainerList translationContainer'))
for example_xml in sense_xml.querySelectorAll("exampleContainerList exampleContainer"): for example_xml in sense_xml.querySelectorAll("exampleContainerList exampleContainer"):
example = Example() example = Example()
example.import_xml(example_xml) example.import_xml(example_xml)

View File

@ -34,7 +34,6 @@ class Translation(Data):
self.source = "" self.source = ""
self.targetLang = "" self.targetLang = ""
self.audio = "" self.audio = ""
self.explanation = ""
self.explanationList = set() self.explanationList = set()
self.tags = [] self.tags = []
@ -82,7 +81,6 @@ class Translation(Data):
# next two are not checked as the also can not be deleted via gui # next two are not checked as the also can not be deleted via gui
# result = result and self.source == "" # result = result and self.source == ""
# result = result and self.targetLang == "" # result = result and self.targetLang == ""
result = result and self.explanation == ""
result = result and len(self.explanationList) == 0 result = result and len(self.explanationList) == 0
result = result and len(self.tags) == 0 result = result and len(self.tags) == 0
return result return result