redid constructors and some other stuff in examples
this is preparation for ske implementation.
This commit is contained in:
parent
fc35a3079b
commit
49875416b2
|
@ -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 = ""
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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:
|
||||
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):
|
||||
|
|
Loading…
Reference in New Issue
Block a user