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
|
from model.data import Data
|
||||||
|
|
||||||
class ComponentLexeme(Data):
|
class ComponentLexeme(Data):
|
||||||
def __init__(self, xml):
|
def __init__(self):
|
||||||
self.other_attributes = {}
|
self.other_attributes = {}
|
||||||
self.text = ""
|
self.text = ""
|
||||||
self.role = ""
|
self.role = ""
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
from lib.snabbdom import h
|
from lib.snabbdom import h
|
||||||
|
|
||||||
class CorpusExample:
|
class CorpusExample:
|
||||||
def __init__(self, example_xml):
|
def __init__(self):
|
||||||
self.other_attributes = {}
|
self.other_attributes = {}
|
||||||
|
|
||||||
|
def import_xml(self, example_xml):
|
||||||
for oth_attr in ["example_id", "modified", "lexical_unit_id", "audio"]:
|
for oth_attr in ["example_id", "modified", "lexical_unit_id", "audio"]:
|
||||||
if example_xml.hasAttribute(oth_attr):
|
if example_xml.hasAttribute(oth_attr):
|
||||||
self.other_attributes[oth_attr] = example_xml.getAttribute(oth_attr)
|
self.other_attributes[oth_attr] = example_xml.getAttribute(oth_attr)
|
||||||
|
|
|
@ -25,7 +25,8 @@ class Example(Data):
|
||||||
self.inner = CorpusExample(inner_xml)
|
self.inner = CorpusExample(inner_xml)
|
||||||
else:
|
else:
|
||||||
inner_xml = example_xml.querySelector("multiwordExample")
|
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:
|
for comp_xml in inner_xml.childNodes:
|
||||||
comp = ComponentLexeme()
|
comp = ComponentLexeme()
|
||||||
|
|
|
@ -4,6 +4,10 @@ from model.example_clusters import ExampleClusters
|
||||||
class MultiwordExample:
|
class MultiwordExample:
|
||||||
def __init__(self, example_xml):
|
def __init__(self, example_xml):
|
||||||
self.other_attributes = {}
|
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"]:
|
for oth_attr in ["lexical_unit_id", "structure_id", "structureName", "audio", "frequency", "logDice"]:
|
||||||
if example_xml.hasAttribute(oth_attr):
|
if example_xml.hasAttribute(oth_attr):
|
||||||
self.other_attributes[oth_attr] = example_xml.getAttribute(oth_attr)
|
self.other_attributes[oth_attr] = example_xml.getAttribute(oth_attr)
|
||||||
|
@ -12,8 +16,6 @@ class MultiwordExample:
|
||||||
|
|
||||||
if example_xml.hasAttribute("type"):
|
if example_xml.hasAttribute("type"):
|
||||||
self.type = example_xml.getAttribute("type")
|
self.type = example_xml.getAttribute("type")
|
||||||
else:
|
|
||||||
self.type = None
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _determine_cluster_number(example_xml):
|
def _determine_cluster_number(example_xml):
|
||||||
|
@ -21,7 +23,7 @@ class MultiwordExample:
|
||||||
return ExampleClusters.first_empty_cluster()
|
return ExampleClusters.first_empty_cluster()
|
||||||
else:
|
else:
|
||||||
cluster = int(example_xml.getAttribute("cluster"))
|
cluster = int(example_xml.getAttribute("cluster"))
|
||||||
ExampleClusters.register_cluster(cluster)
|
ExampleClusters.register_index(cluster)
|
||||||
return cluster
|
return cluster
|
||||||
|
|
||||||
def export(self, doc):
|
def export(self, doc):
|
||||||
|
|
|
@ -13,17 +13,17 @@ class ExampleClusters:
|
||||||
def _first_empty_cluster(self):
|
def _first_empty_cluster(self):
|
||||||
idx = 0
|
idx = 0
|
||||||
while True:
|
while True:
|
||||||
if idx not in self.clusters:
|
if idx not in self.idxs:
|
||||||
self.idxs.add(idx)
|
self._register_index(idx)
|
||||||
return idx
|
return idx
|
||||||
idx += 1
|
idx += 1
|
||||||
|
|
||||||
def _register_cluster(self, idx):
|
def _register_index(self, idx):
|
||||||
if idx not in self.idxs:
|
self.idxs.add(idx)
|
||||||
self.idxs.add(idx)
|
|
||||||
|
|
||||||
def _rebuild_lists(self, model):
|
def _rebuild_lists(self, model):
|
||||||
self.lists = {}
|
self.lists = {}
|
||||||
|
self.idxs = set()
|
||||||
|
|
||||||
for sense in model.entry.senses:
|
for sense in model.entry.senses:
|
||||||
for example in sense.examples:
|
for example in sense.examples:
|
||||||
|
@ -38,6 +38,7 @@ class ExampleClusters:
|
||||||
self.lists[key] = set()
|
self.lists[key] = set()
|
||||||
|
|
||||||
self.lists[key].add(cluster)
|
self.lists[key].add(cluster)
|
||||||
|
self.idxs.add(cluster)
|
||||||
|
|
||||||
for key in self.lists.keys():
|
for key in self.lists.keys():
|
||||||
self.lists[key] = sorted(self.lists[key], key=lambda x: int(x))
|
self.lists[key] = sorted(self.lists[key], key=lambda x: int(x))
|
||||||
|
@ -54,8 +55,8 @@ class ExampleClusters:
|
||||||
return ec._first_empty_cluster()
|
return ec._first_empty_cluster()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def register_cluster(idx):
|
def register_index(idx):
|
||||||
return ec._register_cluster(idx)
|
return ec._register_index(idx)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def rebuild_lists(model):
|
def rebuild_lists(model):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user