2020-02-16 22:25:11 +00:00
|
|
|
from model.example_clusters import ExampleClusters
|
|
|
|
|
|
|
|
|
|
|
|
class MultiwordExample:
|
|
|
|
def __init__(self, example_xml):
|
|
|
|
self.other_attributes = {}
|
2020-03-30 18:31:59 +00:00
|
|
|
self.cluster = -1
|
|
|
|
self.type = None
|
|
|
|
|
|
|
|
def import_xml(self, example_xml):
|
2020-02-16 22:25:11 +00:00
|
|
|
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"))
|
2020-03-30 18:31:59 +00:00
|
|
|
ExampleClusters.register_index(cluster)
|
2020-02-16 22:25:11 +00:00
|
|
|
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])
|
|
|
|
|