lexonomy_custom_editor/src/model/example/multiword_example.py
2020-03-30 20:31:59 +02:00

54 lines
1.7 KiB
Python

from model.example_clusters import ExampleClusters
class MultiwordExample:
def __init__(self, example_xml):
self.other_attributes = {}
self.cluster = -1
self.type = None
def import_xml(self, example_xml):
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)
self.cluster = MultiwordExample._determine_cluster_number(example_xml)
if example_xml.hasAttribute("type"):
self.type = example_xml.getAttribute("type")
@staticmethod
def _determine_cluster_number(example_xml):
if not example_xml.hasAttribute("cluster"):
return ExampleClusters.first_empty_cluster()
else:
cluster = int(example_xml.getAttribute("cluster"))
ExampleClusters.register_index(cluster)
return cluster
def export(self, doc):
result = doc.createElement("multiwordExample")
for key, value in self.other_attributes.items():
result.setAttribute(key, value)
result.setAttribute("cluster", str(self.cluster))
if self.type is not None:
result.setAttribute("type", self.type)
return result
def get_cluster(self):
return self.cluster
def get_structure(self):
if "structureName" in self.other_attributes:
return self.other_attributes["structureName"]
else:
return None
def view(self, components):
return " ".join([comp.text for comp in components])