From f8bd865316d3da87dc524b4d8c21900cc3db1ce0 Mon Sep 17 00:00:00 2001 From: matic_t Date: Thu, 27 Aug 2020 09:38:40 -0700 Subject: [PATCH] Obvious part done. Check why copying example on edit --- src/export.py | 3 --- src/message/example_edit.py | 2 +- src/model/data.py | 2 +- src/model/example/component_lexeme.py | 6 +++++- src/model/example/corpus_example.py | 7 +++++-- src/model/example/example.py | 7 +++---- src/model/example/multiword_example.py | 11 ++++++++--- 7 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/export.py b/src/export.py index 0694e82..c9e2bcd 100644 --- a/src/export.py +++ b/src/export.py @@ -145,11 +145,8 @@ def export_entry(entry): def export_sense(doc, sense, sense_xml): -# sense_xml = doc.createElement("sense") _export_label_list(doc, sense.labels, sense_xml) -# definition_list = translation.original_xml if translation.original_xml != None else doc.createElement("definitionList") - definition_list = sense_xml.querySelector("definitionList") if definition_list is None: definition_list = doc.createElement("definitionList") diff --git a/src/message/example_edit.py b/src/message/example_edit.py index 7b06fc0..1c5e225 100644 --- a/src/message/example_edit.py +++ b/src/message/example_edit.py @@ -60,7 +60,7 @@ class EditExampleText(Message): if example.newly_created: example.newly_created = False sense.examples.append(example) - + console.log(example) idx = 0 for txt in document.getElementsByClassName("example-component-text"): example.components[idx].text = txt.value diff --git a/src/model/data.py b/src/model/data.py index f01543d..20d495c 100644 --- a/src/model/data.py +++ b/src/model/data.py @@ -63,7 +63,7 @@ class Data: return None def overwrite_with_copy(self): - for key, value in dict(self._copy).items(): + for key, value in dict(self).items(): # skip functions and _copy if key == "_copy" or type(value) is None: continue diff --git a/src/model/example/component_lexeme.py b/src/model/example/component_lexeme.py index 0f0c78e..71142fb 100644 --- a/src/model/example/component_lexeme.py +++ b/src/model/example/component_lexeme.py @@ -11,8 +11,10 @@ class ComponentLexeme(Data): self.text = "" self.role = "" self.no_space = False + self.original_xml = None def import_xml(self, xml): + self.original_xml = xml.cloneNode(True) if xml.nodeName == "#text": self.text = xml.data self.role = None @@ -25,6 +27,7 @@ class ComponentLexeme(Data): for oth_attr in ["lexeme_id", "lexical_unit_lexeme_id", "slolex", "kol", "sloleks"]: if xml.hasAttribute(oth_attr): self.other_attributes[oth_attr] = xml.getAttribute(oth_attr) + xml.remove() def isValid(self): return len(self.text) > 0 @@ -32,7 +35,8 @@ class ComponentLexeme(Data): def export(self, doc): if self.role is None: return doc.createTextNode(self.text) - result = doc.createElement("comp") + result = self.original_xml if self.original_xml is not None else doc.createElement("comp") + result.setAttribute("role", self.role) result.textContent = self.text diff --git a/src/model/example/corpus_example.py b/src/model/example/corpus_example.py index aa08ed5..1fc94e7 100644 --- a/src/model/example/corpus_example.py +++ b/src/model/example/corpus_example.py @@ -3,14 +3,17 @@ from lib.snabbdom import h class CorpusExample: def __init__(self): self.other_attributes = {} + self.original_xml = None def import_xml(self, example_xml): for oth_attr in ["example_id", "modified", "lexical_unit_id", "audio"]: if example_xml.hasAttribute(oth_attr): self.other_attributes[oth_attr] = example_xml.getAttribute(oth_attr) - + self.original_xml = example_xml + example_xml.remove() + def export(self, doc, modified): - result = doc.createElement("corpusExample") + result = self.original_xml if self.original_xml is not None else doc.createElement("corpusExample") if modified: result.setAttribute("modified", "true") diff --git a/src/model/example/example.py b/src/model/example/example.py index 86d3a15..09a2a37 100644 --- a/src/model/example/example.py +++ b/src/model/example/example.py @@ -43,20 +43,19 @@ class Example(Data): def import_xml(self, example_xml): self.translations = from_container_list(example_xml.querySelectorAll("translationContainerList translationContainer")) self.original_xml = example_xml.cloneNode(True) - if example_xml.hasAttribute("modified"): self.edited = example_xml.getAttribute("modified") == "true" - inner_xml = example_xml.querySelector("corpusExample") + inner_xml = self.original_xml.querySelector("corpusExample") if inner_xml is not None: self.inner = CorpusExample() else: - inner_xml = example_xml.querySelector("multiwordExample") + inner_xml = self.original_xml.querySelector("multiwordExample") self.inner = MultiwordExample() self.inner.import_xml(inner_xml) - for idx, comp_xml in enumerate(inner_xml.childNodes): + for idx, comp_xml in enumerate(self.inner.original_xml.childNodes): comp = ComponentLexeme() comp.import_xml(comp_xml) if comp.isValid(): diff --git a/src/model/example/multiword_example.py b/src/model/example/multiword_example.py index 6ee6918..c511370 100644 --- a/src/model/example/multiword_example.py +++ b/src/model/example/multiword_example.py @@ -6,8 +6,10 @@ class MultiwordExample: self.other_attributes = {} self.cluster = -1 self.type = None + self.original_xml = None def import_xml(self, example_xml): + self.original_xml = example_xml.cloneNode(True) for oth_attr in ["lexical_unit_id", "structure_id", "structureName", "audio", "frequency", "logDice"]: if example_xml.hasAttribute(oth_attr): self.other_attributes[oth_attr] = example_xml.getAttribute(oth_attr) @@ -16,7 +18,10 @@ class MultiwordExample: if example_xml.hasAttribute("type"): self.type = example_xml.getAttribute("type") - + + + example_xml.remove() + @staticmethod def _determine_cluster_number(example_xml): if not example_xml.hasAttribute("cluster"): @@ -27,8 +32,8 @@ class MultiwordExample: return cluster def export(self, doc, _modified): - result = doc.createElement("multiwordExample") - + result = self.original_xml if self.original_xml is not None else doc.createElement("multiwordExample") + # result = doc.createElement("multiwordExample") for key, value in self.other_attributes.items(): result.setAttribute(key, value)