|
|
@ -3,15 +3,6 @@ from model.translation import from_container_list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Example(Editable):
|
|
|
|
class Example(Editable):
|
|
|
|
@staticmethod
|
|
|
|
|
|
|
|
def from_xml(example_xml):
|
|
|
|
|
|
|
|
ce_xml = example_xml.querySelector("corpusExample")
|
|
|
|
|
|
|
|
if ce_xml is not None:
|
|
|
|
|
|
|
|
return CorpusExample(example_xml)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return MultiwordExample(example_xml)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
@staticmethod
|
|
|
|
def add_clusters(entry):
|
|
|
|
def add_clusters(entry):
|
|
|
|
nocluster_examples = []
|
|
|
|
nocluster_examples = []
|
|
|
@ -32,25 +23,38 @@ class Example(Editable):
|
|
|
|
cnum += 1
|
|
|
|
cnum += 1
|
|
|
|
taken_clusters.append(cnum)
|
|
|
|
taken_clusters.append(cnum)
|
|
|
|
|
|
|
|
|
|
|
|
example.cluster = cnum
|
|
|
|
example.set_cluster(cnum)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, example_xml):
|
|
|
|
def __init__(self, example_xml):
|
|
|
|
self.translations = from_container_list(example_xml.querySelectorAll("translationContainer"))
|
|
|
|
self.translations = from_container_list(example_xml.querySelectorAll("translationContainer"))
|
|
|
|
self.components = [ComponentLexeme(el) for el in example_xml.querySelectorAll("comp")]
|
|
|
|
self.components = [ComponentLexeme(el) for el in example_xml.querySelectorAll("comp")]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ce_xml = example_xml.querySelector("corpusExample")
|
|
|
|
|
|
|
|
if ce_xml is not None:
|
|
|
|
|
|
|
|
self.inner = CorpusExample(example_xml)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
self.inner = MultiwordExample(example_xml)
|
|
|
|
|
|
|
|
|
|
|
|
def get_cluster(self):
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_valid_cluster(self):
|
|
|
|
def export(self, doc):
|
|
|
|
return None
|
|
|
|
result = doc.createElement("exampleContainer")
|
|
|
|
|
|
|
|
result.appendChild(self.inner.export(doc))
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def text(self):
|
|
|
|
def text(self):
|
|
|
|
return " ".join([comp.text for comp in self.components])
|
|
|
|
return " ".join([comp.text for comp in self.components])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_cluster(self):
|
|
|
|
|
|
|
|
return self.inner.get_cluster()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_valid_cluster(self):
|
|
|
|
|
|
|
|
return self.inner.get_valid_cluster()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_cluster(self, cluster):
|
|
|
|
|
|
|
|
self.inner.cluster = cluster
|
|
|
|
|
|
|
|
|
|
|
|
class CorpusExample(Example):
|
|
|
|
class CorpusExample:
|
|
|
|
def __init__(self, example_xml):
|
|
|
|
def __init__(self, example_xml):
|
|
|
|
super().__init__(example_xml)
|
|
|
|
super().__init__(example_xml)
|
|
|
|
xml = example_xml.querySelector("corpusExample")
|
|
|
|
xml = example_xml.querySelector("corpusExample")
|
|
|
@ -60,8 +64,21 @@ class CorpusExample(Example):
|
|
|
|
if xml.hasAttribute(oth_attr):
|
|
|
|
if xml.hasAttribute(oth_attr):
|
|
|
|
self.other_attributes[oth_attr] = xml.getAttribute(oth_attr)
|
|
|
|
self.other_attributes[oth_attr] = xml.getAttribute(oth_attr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def export(self, doc):
|
|
|
|
|
|
|
|
result = doc.createElement("corpusExample")
|
|
|
|
|
|
|
|
for comp in self.components:
|
|
|
|
|
|
|
|
result.appendChild(comp.export(doc))
|
|
|
|
|
|
|
|
for key, value in self.other_attributes.items():
|
|
|
|
|
|
|
|
result.setAttribute(key, value)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
class MultiwordExample(Example):
|
|
|
|
def get_cluster(self):
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_valid_cluster(self):
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MultiwordExample:
|
|
|
|
def __init__(self, example_xml):
|
|
|
|
def __init__(self, example_xml):
|
|
|
|
super().__init__(example_xml)
|
|
|
|
super().__init__(example_xml)
|
|
|
|
xml = example_xml.querySelector("multiwordExample")
|
|
|
|
xml = example_xml.querySelector("multiwordExample")
|
|
|
@ -77,6 +94,20 @@ class MultiwordExample(Example):
|
|
|
|
self.cluster_valid = True
|
|
|
|
self.cluster_valid = True
|
|
|
|
self.cluster = int(xml.getAttribute("cluster"))
|
|
|
|
self.cluster = int(xml.getAttribute("cluster"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def export(self, doc):
|
|
|
|
|
|
|
|
result = doc.createElement("multiwordExample")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for comp in self.components:
|
|
|
|
|
|
|
|
result.appendChild(comp.export(doc))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for key, value in self.other_attributes.items():
|
|
|
|
|
|
|
|
result.setAttribute(key, value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.cluster_valid:
|
|
|
|
|
|
|
|
result.setAttribute("cluster", str(self.cluster))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def get_cluster(self):
|
|
|
|
def get_cluster(self):
|
|
|
|
return self.cluster
|
|
|
|
return self.cluster
|
|
|
|
|
|
|
|
|
|
|
@ -93,3 +124,15 @@ class ComponentLexeme:
|
|
|
|
for oth_attr in ["lexical_unit_lexeme_id", "slolex", "kol"]:
|
|
|
|
for oth_attr in ["lexical_unit_lexeme_id", "slolex", "kol"]:
|
|
|
|
if xml.hasAttribute(oth_attr):
|
|
|
|
if xml.hasAttribute(oth_attr):
|
|
|
|
self.other_attributes[oth_attr] = xml.getAttribute(oth_attr)
|
|
|
|
self.other_attributes[oth_attr] = xml.getAttribute(oth_attr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def export(self, doc):
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|