You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lexonomy_custom_editor/src/model/example/component_lexeme.py

57 lines
1.7 KiB

from model.data import Data
class ComponentLexeme(Data):
def __init__(self):
self.other_attributes = {}
self.text = ""
self.role = ""
self.no_space = False
def import_xml(self, xml):
if xml.nodeName == "#text":
self.text = xml.data
self.role = None
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):
self.other_attributes[oth_attr] = xml.getAttribute(oth_attr)
def isValid(self):
return len(self.text) > 0
def export(self, doc, is_multiword, last_component):
if self.role is None:
return doc.createTextNode(self.text)
result = doc.createElement("comp")
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"
if self.role == "headword":
result += ".comp-role-headword"
return result