Adding nospace flag and modified flag to multiword example

This commit is contained in:
2020-06-11 18:47:09 +02:00
parent 6a2507a9c2
commit 73ef517c8a
8 changed files with 70 additions and 27 deletions

View File

@@ -5,6 +5,7 @@ class ComponentLexeme(Data):
self.other_attributes = {}
self.text = ""
self.role = ""
self.no_space = False
def import_xml(self, xml):
if xml.nodeName == "#text":
@@ -13,6 +14,9 @@ class ComponentLexeme(Data):
else:
self.text = xml.textContent
self.role = xml.getAttribute("role")
if xml.hasAttribute("space"):
self.no_space = xml.getAttribute("space") == "false"
for oth_attr in ["lexical_unit_lexeme_id", "slolex", "kol"]:
if xml.hasAttribute(oth_attr):
@@ -21,7 +25,7 @@ class ComponentLexeme(Data):
def isValid(self):
return len(self.text) > 0
def export(self, doc):
def export(self, doc, is_multiword, last_component):
if self.role is None:
return doc.createTextNode(self.text)
@@ -29,12 +33,17 @@ class ComponentLexeme(Data):
result.setAttribute("role", self.role)
result.textContent = self.text
# no space is only allowed in in multiword examples that are not last component
if self.no_space is True and is_multiword and not last_component:
result.setAttribute("space", "false")
for key, value in self.other_attributes.items():
result.setAttribute(key, value)
return result
def view_style(self):
# no-space is handled in multiword-example directly
result = ".comp-text"
if self.role is not None:
result += ".comp-role"

View File

@@ -9,8 +9,11 @@ class CorpusExample:
if example_xml.hasAttribute(oth_attr):
self.other_attributes[oth_attr] = example_xml.getAttribute(oth_attr)
def export(self, doc):
def export(self, doc, modified):
result = doc.createElement("corpusExample")
if modified:
result.setAttribute("modified", "true")
for key, value in self.other_attributes.items():
result.setAttribute(key, value)
return result

View File

@@ -32,7 +32,7 @@ class Example(Data):
self.inner.import_xml(inner_xml)
for comp_xml in inner_xml.childNodes:
for idx, comp_xml in enumerate(inner_xml.childNodes):
comp = ComponentLexeme()
comp.import_xml(comp_xml)
if comp.isValid():
@@ -41,13 +41,11 @@ class Example(Data):
def export(self, doc):
result = doc.createElement("exampleContainer")
if self.edited:
result.setAttribute("modified", "true")
inner = self.inner.export(doc)
inner = self.inner.export(doc, self.edited)
# TODO: bad quick fix
for comp in self.components:
inner.appendChild(comp.export(doc))
for idx, comp in enumerate(self.components):
inner.appendChild(comp.export(
doc, self.is_multiword(), idx == len(self.components) - 1))
result.appendChild(inner)
return result

View File

@@ -26,7 +26,7 @@ class MultiwordExample:
ExampleClusters.register_index(cluster)
return cluster
def export(self, doc):
def export(self, doc, _modified):
result = doc.createElement("multiwordExample")
for key, value in self.other_attributes.items():
@@ -49,5 +49,11 @@ class MultiwordExample:
return None
def view(self, components):
return " ".join([comp.text for comp in components])
result = ""
for comp in components:
result += comp.text
if not comp.no_space:
result += " "
return result.strip()