You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.7 KiB
52 lines
1.7 KiB
from model.example import Example
|
|
from model.translation import from_container_list
|
|
from model.editable import Editable
|
|
from model.tags import import_label_list
|
|
|
|
|
|
cluster_min = 0
|
|
|
|
|
|
class Sense(Editable):
|
|
def __init__(self, sense_xml):
|
|
global cluster_min
|
|
|
|
self.definition = {}
|
|
for definition in sense_xml.querySelectorAll("definitionList definition"):
|
|
key = definition.getAttribute("type")
|
|
self.definition[key] = definition.textContent
|
|
|
|
self.labels = import_label_list("sense > labelList label", sense_xml)
|
|
self.translations = from_container_list(
|
|
sense_xml.querySelectorAll("translationContainerList translationContainer"))
|
|
|
|
cluster_mappings = {}
|
|
cluster_info = (cluster_mappings, cluster_min)
|
|
|
|
self.examples = [Example(example_xml, cluster_info) for example_xml in
|
|
sense_xml.querySelectorAll("exampleContainerList exampleContainer")]
|
|
|
|
# set limit for example cluster
|
|
cluster_min =max(cluster_mappings.values()) + 2
|
|
|
|
self._original_examples = set([cluster_min - 1])
|
|
self._original_examples = set(self.example_clusters())
|
|
|
|
def merge_labels(self):
|
|
return ", ".join(val for _, val in self.labels)
|
|
|
|
def example_clusters(self):
|
|
result = self._original_examples
|
|
for ex in self.examples:
|
|
cluster = ex.get_cluster()
|
|
if cluster is not None:
|
|
result.add(cluster)
|
|
|
|
return sorted(result)
|
|
|
|
@staticmethod
|
|
def reset_cluster_count():
|
|
global cluster_min
|
|
cluster_min = 0
|
|
|