much cleaner way to handle "last component in multiword example does not have a space"
This commit is contained in:
parent
9f116f3452
commit
4cc3c2cdc6
|
@ -1,6 +1,11 @@
|
|||
from model.data import Data
|
||||
|
||||
|
||||
class ComponentLexeme(Data):
|
||||
# special value for last component that evaluates to True by default but is not
|
||||
# exported to true
|
||||
LAST_COMPONENT_SPACE = "last component does not have space"
|
||||
|
||||
def __init__(self):
|
||||
self.other_attributes = {}
|
||||
self.text = ""
|
||||
|
@ -25,7 +30,7 @@ class ComponentLexeme(Data):
|
|||
def isValid(self):
|
||||
return len(self.text) > 0
|
||||
|
||||
def export(self, doc, is_multiword, last_component):
|
||||
def export(self, doc):
|
||||
if self.role is None:
|
||||
return doc.createTextNode(self.text)
|
||||
|
||||
|
@ -33,8 +38,7 @@ 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:
|
||||
if self.no_space and self.no_space != self.LAST_COMPONENT_SPACE:
|
||||
result.setAttribute("space", "false")
|
||||
|
||||
for key, value in self.other_attributes.items():
|
||||
|
|
|
@ -17,6 +17,12 @@ class Example(Data):
|
|||
self.components = []
|
||||
self.edited = False
|
||||
|
||||
# removes space from last component if multiword example
|
||||
def check_multiword_components(self):
|
||||
if self.is_multiword():
|
||||
self.components[len(self.components) - 1].no_space = ComponentLexeme.LAST_COMPONENT_SPACE
|
||||
|
||||
|
||||
def import_xml(self, example_xml):
|
||||
self.translations = from_container_list(example_xml.querySelectorAll("translationContainer"))
|
||||
|
||||
|
@ -38,14 +44,17 @@ class Example(Data):
|
|||
if comp.isValid():
|
||||
self.components.append(comp)
|
||||
|
||||
self.check_multiword_components()
|
||||
|
||||
def export(self, doc):
|
||||
self.check_multiword_components()
|
||||
|
||||
result = doc.createElement("exampleContainer")
|
||||
|
||||
inner = self.inner.export(doc, self.edited)
|
||||
# TODO: bad quick fix
|
||||
for idx, comp in enumerate(self.components):
|
||||
inner.appendChild(comp.export(
|
||||
doc, self.is_multiword(), idx == len(self.components) - 1))
|
||||
for comp in self.components:
|
||||
inner.appendChild(comp.export(doc))
|
||||
|
||||
result.appendChild(inner)
|
||||
return result
|
||||
|
|
Loading…
Reference in New Issue
Block a user