2020-02-16 22:25:11 +00:00
|
|
|
from model.data import Data
|
|
|
|
|
|
|
|
class ComponentLexeme(Data):
|
2020-03-30 18:31:59 +00:00
|
|
|
def __init__(self):
|
2020-02-16 22:25:11 +00:00
|
|
|
self.other_attributes = {}
|
2020-02-16 23:00:03 +00:00
|
|
|
self.text = ""
|
|
|
|
self.role = ""
|
|
|
|
|
|
|
|
def import_xml(self, xml):
|
2020-02-16 22:25:11 +00:00
|
|
|
if xml.nodeName == "#text":
|
|
|
|
self.text = xml.data
|
|
|
|
self.role = None
|
|
|
|
else:
|
|
|
|
self.text = xml.textContent
|
|
|
|
self.role = xml.getAttribute("role")
|
|
|
|
|
|
|
|
for oth_attr in ["lexical_unit_lexeme_id", "slolex", "kol"]:
|
|
|
|
if xml.hasAttribute(oth_attr):
|
|
|
|
self.other_attributes[oth_attr] = xml.getAttribute(oth_attr)
|
|
|
|
|
|
|
|
self.text = self.text.strip()
|
|
|
|
|
|
|
|
def isValid(self):
|
|
|
|
return len(self.text) > 0
|
|
|
|
|
|
|
|
def export(self, doc):
|
|
|
|
if self.role is None:
|
|
|
|
return doc.createTextNode(self.text)
|
|
|
|
|
|
|
|
result = doc.createElement("comp")
|
|
|
|
result.setAttribute("role", self.role)
|
|
|
|
result.textContent = self.text
|
|
|
|
|
|
|
|
for key, value in self.other_attributes.items():
|
|
|
|
result.setAttribute(key, value)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
def view_style(self):
|
|
|
|
result = ".comp-text"
|
|
|
|
if self.role is not None:
|
|
|
|
result += ".comp-role"
|
|
|
|
if self.role == "headword":
|
|
|
|
result += ".comp-role-headword"
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|