parent
be90c9dc89
commit
3844c7025b
@ -0,0 +1,65 @@
|
||||
class ExampleClusters:
|
||||
def __init__(self):
|
||||
self.idxs = set()
|
||||
self.lists = {}
|
||||
|
||||
@staticmethod
|
||||
def get_key(sense, example):
|
||||
sense_idx = sense.original_idx
|
||||
structure_name = example.get_structure()
|
||||
key = "{}-{}".format(sense_idx, structure_name)
|
||||
return key
|
||||
|
||||
def _first_empty_cluster(self):
|
||||
idx = 0
|
||||
while True:
|
||||
if idx not in self.clusters:
|
||||
self.idxs.add(idx)
|
||||
return idx
|
||||
idx += 1
|
||||
|
||||
def _register_cluster(self, idx):
|
||||
if idx not in self.idxs:
|
||||
self.idxs.add(idx)
|
||||
|
||||
def _rebuild_lists(self, model):
|
||||
self.lists = {}
|
||||
|
||||
for sense in model.entry.senses:
|
||||
for example in sense.examples:
|
||||
structure = example.get_structure()
|
||||
key = ExampleClusters.get_key(sense, example)
|
||||
|
||||
if key not in self.lists:
|
||||
self.lists[key] = set()
|
||||
|
||||
self.lists[key].add(example.get_cluster())
|
||||
|
||||
for key in self.lists.keys():
|
||||
self.lists[key] = sorted(self.lists[key], key=lambda x: x)
|
||||
|
||||
def _get_list(self, sense, example):
|
||||
key = ExampleClusters.get_key(sense, example)
|
||||
if key in self.lists:
|
||||
return self.lists[key]
|
||||
else:
|
||||
return []
|
||||
|
||||
@staticmethod
|
||||
def first_empty_cluster():
|
||||
return ec._first_empty_cluster()
|
||||
|
||||
@staticmethod
|
||||
def register_cluster(idx):
|
||||
return ec._register_cluster(idx)
|
||||
|
||||
@staticmethod
|
||||
def rebuild_lists(model):
|
||||
return ec._rebuild_lists(model)
|
||||
|
||||
@staticmethod
|
||||
def get_list(sense, example):
|
||||
return ec._get_list(sense, example)
|
||||
|
||||
|
||||
ec = ExampleClusters()
|
Loading…
Reference in new issue