|
|
|
@ -1,14 +1,23 @@
|
|
|
|
|
from model.data import Data as Editable
|
|
|
|
|
from model.data import Data
|
|
|
|
|
from model.translation import from_container_list
|
|
|
|
|
from lib.snabbdom import h
|
|
|
|
|
import message as M
|
|
|
|
|
from view import View
|
|
|
|
|
from view.utils import show_toggle_cluster_buttons
|
|
|
|
|
|
|
|
|
|
from model.example.component_lexeme import ComponentLexeme
|
|
|
|
|
from model.example.corpus_example import CorpusExample
|
|
|
|
|
from model.example.multiword_example import MultiwordExample
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Example(Editable):
|
|
|
|
|
def __init__(self, example_xml):
|
|
|
|
|
class Example(Data):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.translations = []
|
|
|
|
|
self.inner = None
|
|
|
|
|
self.components = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def import_xml(self, example_xml):
|
|
|
|
|
self.translations = from_container_list(example_xml.querySelectorAll("translationContainer"))
|
|
|
|
|
|
|
|
|
|
inner_xml = example_xml.querySelector("corpusExample")
|
|
|
|
@ -18,9 +27,11 @@ class Example(Editable):
|
|
|
|
|
inner_xml = example_xml.querySelector("multiwordExample")
|
|
|
|
|
self.inner = MultiwordExample(inner_xml)
|
|
|
|
|
|
|
|
|
|
all_components = [ComponentLexeme(el) for el in inner_xml.childNodes]
|
|
|
|
|
self.components = [comp for comp in all_components if comp.isValid()]
|
|
|
|
|
|
|
|
|
|
for comp_xml in inner_xml.childNodes:
|
|
|
|
|
comp = ComponentLexeme()
|
|
|
|
|
comp.import_xml(comp_xml)
|
|
|
|
|
if comp.isValid():
|
|
|
|
|
self.components.append(comp)
|
|
|
|
|
|
|
|
|
|
def export(self, doc):
|
|
|
|
|
result = doc.createElement("exampleContainer")
|
|
|
|
@ -33,8 +44,43 @@ class Example(Editable):
|
|
|
|
|
result.appendChild(inner)
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def view(self):
|
|
|
|
|
return self.inner.view(self.components)
|
|
|
|
|
def view(self, model, sense):
|
|
|
|
|
example_tag = "div.example-rest"
|
|
|
|
|
if self in model.chosen_examples:
|
|
|
|
|
example_tag += ".example-chosen"
|
|
|
|
|
|
|
|
|
|
cluster = self.get_cluster()
|
|
|
|
|
dot_attr = {"style": { "visibility": "visible" if cluster is None else "hidden"}}
|
|
|
|
|
|
|
|
|
|
example_content = []
|
|
|
|
|
if cluster is not None:
|
|
|
|
|
example_content.append(h("span.example-cluster", {}, str(cluster + 1)))
|
|
|
|
|
|
|
|
|
|
example_text_inner_tag = "span.example-text-{}".format(self.get_view_type())
|
|
|
|
|
example_content.append(h(example_text_inner_tag, {}, self.inner.view(self.components)))
|
|
|
|
|
|
|
|
|
|
other_attributes = self.get_other_attributes()
|
|
|
|
|
if "frequency" in other_attributes:
|
|
|
|
|
example_content.append(h("span.example-frequency", {}, other_attributes["frequency"]))
|
|
|
|
|
if "logDice" in other_attributes:
|
|
|
|
|
example_content.append(h("span.example-logdice", {}, other_attributes["logDice"]))
|
|
|
|
|
|
|
|
|
|
parent_display = "inherit"
|
|
|
|
|
if not model.examples_shown and not self.is_multiword():
|
|
|
|
|
parent_display = "none"
|
|
|
|
|
|
|
|
|
|
clusters_display = "inherit"
|
|
|
|
|
if not model.clusters_shown:
|
|
|
|
|
clusters_display = "none"
|
|
|
|
|
|
|
|
|
|
return h("div.example", {"style": {"display": parent_display}}, [
|
|
|
|
|
h("div.example-dot", dot_attr, "▣"),
|
|
|
|
|
h(example_tag, {}, [
|
|
|
|
|
h("span.example-text", {"on": {"click": M.msg(M.ShowExampleMenu, self)} }, example_content),
|
|
|
|
|
h("div.example-translation-list", {}, [
|
|
|
|
|
h("div.example-translation", {}, View.view_translations(self.translations, self, model))]),
|
|
|
|
|
h("div.example-clusters",
|
|
|
|
|
{"style": {"display": clusters_display }}, show_toggle_cluster_buttons(sense, self))])])
|
|
|
|
|
|
|
|
|
|
def get_cluster(self):
|
|
|
|
|
return self.inner.get_cluster()
|
|
|
|
|