diff --git a/src/model/example/component_lexeme.py b/src/model/example/component_lexeme.py index bf59ef6..de91e19 100644 --- a/src/model/example/component_lexeme.py +++ b/src/model/example/component_lexeme.py @@ -1,7 +1,7 @@ from model.data import Data class ComponentLexeme(Data): - def __init__(self, xml): + def __init__(self): self.other_attributes = {} self.text = "" self.role = "" diff --git a/src/model/example/corpus_example.py b/src/model/example/corpus_example.py index 57becb3..06184fc 100644 --- a/src/model/example/corpus_example.py +++ b/src/model/example/corpus_example.py @@ -1,8 +1,10 @@ from lib.snabbdom import h class CorpusExample: - def __init__(self, example_xml): + def __init__(self): self.other_attributes = {} + + def import_xml(self, example_xml): for oth_attr in ["example_id", "modified", "lexical_unit_id", "audio"]: if example_xml.hasAttribute(oth_attr): self.other_attributes[oth_attr] = example_xml.getAttribute(oth_attr) diff --git a/src/model/example/example.py b/src/model/example/example.py index 16541e5..c5e3d5d 100644 --- a/src/model/example/example.py +++ b/src/model/example/example.py @@ -25,7 +25,8 @@ class Example(Data): self.inner = CorpusExample(inner_xml) else: inner_xml = example_xml.querySelector("multiwordExample") - self.inner = MultiwordExample(inner_xml) + self.inner = MultiwordExample() + self.inner.import_xml(inner_xml) for comp_xml in inner_xml.childNodes: comp = ComponentLexeme() diff --git a/src/model/example/multiword_example.py b/src/model/example/multiword_example.py index e550658..421cca6 100644 --- a/src/model/example/multiword_example.py +++ b/src/model/example/multiword_example.py @@ -4,6 +4,10 @@ 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) @@ -12,8 +16,6 @@ class MultiwordExample: if example_xml.hasAttribute("type"): self.type = example_xml.getAttribute("type") - else: - self.type = None @staticmethod def _determine_cluster_number(example_xml): @@ -21,7 +23,7 @@ class MultiwordExample: return ExampleClusters.first_empty_cluster() else: cluster = int(example_xml.getAttribute("cluster")) - ExampleClusters.register_cluster(cluster) + ExampleClusters.register_index(cluster) return cluster def export(self, doc): diff --git a/src/model/example_clusters.py b/src/model/example_clusters.py index ccdf9af..c0f0f26 100644 --- a/src/model/example_clusters.py +++ b/src/model/example_clusters.py @@ -13,17 +13,17 @@ class ExampleClusters: def _first_empty_cluster(self): idx = 0 while True: - if idx not in self.clusters: - self.idxs.add(idx) + if idx not in self.idxs: + self._register_index(idx) return idx idx += 1 - def _register_cluster(self, idx): - if idx not in self.idxs: - self.idxs.add(idx) + def _register_index(self, idx): + self.idxs.add(idx) def _rebuild_lists(self, model): self.lists = {} + self.idxs = set() for sense in model.entry.senses: for example in sense.examples: @@ -38,6 +38,7 @@ class ExampleClusters: self.lists[key] = set() self.lists[key].add(cluster) + self.idxs.add(cluster) for key in self.lists.keys(): self.lists[key] = sorted(self.lists[key], key=lambda x: int(x)) @@ -54,8 +55,8 @@ class ExampleClusters: return ec._first_empty_cluster() @staticmethod - def register_cluster(idx): - return ec._register_cluster(idx) + def register_index(idx): + return ec._register_index(idx) @staticmethod def rebuild_lists(model):