from model.example_clusters import ExampleClusters class MultiwordExample: def __init__(self, example_xml): self.other_attributes = {} 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") else: self.type = None @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_cluster(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])