Merge pull request 'mt-additional-xml-shema-support' (#6) from mt-additional-xml-shema-support into master
Reviewed-on: #6
This commit is contained in:
commit
5fe2bb62bb
|
@ -156,16 +156,7 @@
|
||||||
vertical-align: super;
|
vertical-align: super;
|
||||||
font-size: 0.7em;
|
font-size: 0.7em;
|
||||||
}
|
}
|
||||||
.translation-explanation:not(:empty) {
|
|
||||||
font-style: italic;
|
|
||||||
|
|
||||||
&:before {
|
|
||||||
content: '[';
|
|
||||||
}
|
|
||||||
&:after {
|
|
||||||
content: ']';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.translation-add {
|
.translation-add {
|
||||||
|
@ -175,6 +166,20 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.explanations:not(:empty) {
|
||||||
|
font-style: italic;
|
||||||
|
|
||||||
|
&:not(.solo) {
|
||||||
|
&:before {
|
||||||
|
content: '[';
|
||||||
|
}
|
||||||
|
|
||||||
|
&:after {
|
||||||
|
content: ']';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.example {
|
.example {
|
||||||
clear: left;
|
clear: left;
|
||||||
margin-left: 1em;
|
margin-left: 1em;
|
||||||
|
|
|
@ -5,7 +5,7 @@ from model.tags import export_tag
|
||||||
def export_to_xml(model):
|
def export_to_xml(model):
|
||||||
xml_document = export_entry(model.entry)
|
xml_document = export_entry(model.entry)
|
||||||
serializer = __new__(XMLSerializer())
|
serializer = __new__(XMLSerializer())
|
||||||
return serializer.serializeToString(xml_document);
|
return serializer.serializeToString(xml_document)
|
||||||
|
|
||||||
|
|
||||||
def export_entry(entry):
|
def export_entry(entry):
|
||||||
|
@ -23,9 +23,14 @@ def export_entry(entry):
|
||||||
|
|
||||||
headword = doc.createElement("headword")
|
headword = doc.createElement("headword")
|
||||||
headword_lemma = doc.createElement("lemma")
|
headword_lemma = doc.createElement("lemma")
|
||||||
|
|
||||||
|
# headword_lemma = entry.original_xml.querySelector("head headword lemma")
|
||||||
|
|
||||||
headword_lemma.textContent = entry.headword
|
headword_lemma.textContent = entry.headword
|
||||||
if entry.headword_type is not None:
|
if entry.headword_type is not None:
|
||||||
headword_lemma.setAttribute("type", entry.headword_type)
|
headword_lemma.setAttribute("type", entry.headword_type)
|
||||||
|
if entry.headword_audio is not None:
|
||||||
|
headword_lemma.setAttribute("audio", entry.headword_audio)
|
||||||
headword.appendChild(headword_lemma)
|
headword.appendChild(headword_lemma)
|
||||||
head.appendChild(headword)
|
head.appendChild(headword)
|
||||||
|
|
||||||
|
@ -52,11 +57,18 @@ def export_entry(entry):
|
||||||
lexunit.appendChild(lexeme)
|
lexunit.appendChild(lexeme)
|
||||||
head.appendChild(lexunit)
|
head.appendChild(lexunit)
|
||||||
|
|
||||||
grammar = doc.createElement("grammar")
|
# Example of keeping original xml and adding changes to it only
|
||||||
grammar_category = doc.createElement("category")
|
grammar_category = entry.original_xml.querySelector("head grammar category")
|
||||||
|
if grammar_category is None:
|
||||||
|
grammar = doc.createElement("grammar")
|
||||||
|
grammar_category = doc.createElement("category")
|
||||||
|
grammar.appendChild(grammar_category)
|
||||||
|
entry.original_xml.querySelector("head").appendChild(grammar_category)
|
||||||
|
|
||||||
grammar_category.textContent = entry.grammar
|
grammar_category.textContent = entry.grammar
|
||||||
grammar.appendChild(grammar_category)
|
|
||||||
head.appendChild(grammar)
|
head.appendChild(entry.original_xml.querySelector("head grammar"))
|
||||||
|
|
||||||
|
|
||||||
if len(entry.measure) > 0:
|
if len(entry.measure) > 0:
|
||||||
measure_list = doc.createElement("measureList")
|
measure_list = doc.createElement("measureList")
|
||||||
|
@ -125,7 +137,9 @@ def export_sense(doc, sense):
|
||||||
|
|
||||||
for example in sense.examples:
|
for example in sense.examples:
|
||||||
example_container = example.export(doc)
|
example_container = example.export(doc)
|
||||||
export_translation_list(doc, example, example_container)
|
translation_container_list = doc.createElement("translationContainerList")
|
||||||
|
export_translation_list(doc, example, translation_container_list)
|
||||||
|
example_container.appendChild(translation_container_list)
|
||||||
example_container_list.appendChild(example_container)
|
example_container_list.appendChild(example_container)
|
||||||
|
|
||||||
return sense_xml
|
return sense_xml
|
||||||
|
@ -146,26 +160,27 @@ def export_translation(doc, translation):
|
||||||
actual_t.textContent = translation.translation
|
actual_t.textContent = translation.translation
|
||||||
actual_t.setAttribute("targetLang", translation.targetLang)
|
actual_t.setAttribute("targetLang", translation.targetLang)
|
||||||
|
|
||||||
|
if translation.audio:
|
||||||
|
actual_t.setAttribute("audio", translation.audio)
|
||||||
|
|
||||||
if translation.source:
|
if translation.source:
|
||||||
actual_t.setAttribute("source", translation.source)
|
actual_t.setAttribute("source", translation.source)
|
||||||
translation_xml.appendChild(actual_t)
|
translation_xml.appendChild(actual_t)
|
||||||
|
|
||||||
explanationList = doc.createElement("explanationList")
|
if len(translation.explanationList) > 0 :
|
||||||
|
explanationList = _export_explanation_list(doc, translation.explanationList)
|
||||||
for explanation in translation.explanationList:
|
translation_xml.appendChild(explanationList)
|
||||||
el = doc.createElement("explanation")
|
|
||||||
el.textContent = explanation
|
|
||||||
explanationList.appendChild(el)
|
|
||||||
|
|
||||||
translation_xml.appendChild(explanationList)
|
|
||||||
|
|
||||||
|
|
||||||
explanation = doc.createElement("explanation")
|
|
||||||
explanation.textContent = translation.explanation
|
|
||||||
translation_xml.appendChild(explanation)
|
|
||||||
|
|
||||||
return translation_xml
|
return translation_xml
|
||||||
|
|
||||||
|
def _export_explanation_list(doc, lst):
|
||||||
|
result = doc.createElement('explanationList')
|
||||||
|
for explanation in lst:
|
||||||
|
result.appendChild(explanation.export(doc))
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
def _export_label_list(doc, lst):
|
def _export_label_list(doc, lst):
|
||||||
result = doc.createElement("labelList")
|
result = doc.createElement("labelList")
|
||||||
|
|
|
@ -10,16 +10,19 @@ def generic_list_getter():
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# Formats data from inputs to name-value objects
|
# Formats data from inputs to name-value objects
|
||||||
def homonymy_list_getter():
|
def double_list_getter(firstParameter, secondParameter, allowEmptyField = False):
|
||||||
result = []
|
result = []
|
||||||
for row in document.getElementsByClassName("label-list-row"):
|
for row in document.getElementsByClassName("double-list-row"):
|
||||||
value = row.querySelector(".value-input").value
|
firstValue = row.querySelector("." + firstParameter + "-input").value
|
||||||
name = row.querySelector(".name-input").value
|
secondValue = row.querySelector("." + secondParameter + "-input").value
|
||||||
|
|
||||||
if ("" in [name, value]):
|
if (allowEmptyField is False and '' in [firstValue, secondValue]):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
result.append({"name": name, "value": value})
|
if (allowEmptyField is True and all('' == value or value.isspace() for value in [firstValue, secondValue])):
|
||||||
|
continue
|
||||||
|
|
||||||
|
result.append({firstParameter: firstValue, secondParameter: secondValue})
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ class EditVariants(Message):
|
||||||
|
|
||||||
class EditHomonymy(Message):
|
class EditHomonymy(Message):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
homonymy = common_accessors.homonymy_list_getter()
|
homonymy = common_accessors.double_list_getter("value", "name")
|
||||||
model.entry.homonymy = homonymy
|
model.entry.homonymy = homonymy
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import message.common_accessors as common_accessors
|
||||||
from browser import document, window
|
from browser import document, window
|
||||||
from model.translation import Translation
|
from model.translation import Translation
|
||||||
from model.sense import Sense
|
from model.sense import Sense
|
||||||
|
from model.explanation import Explanation
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,9 +14,14 @@ class EditTranslation(DataChgClickMessage):
|
||||||
self.old_cluster_idx = self.get_arg(1, int)
|
self.old_cluster_idx = self.get_arg(1, int)
|
||||||
|
|
||||||
self.translation.translation = document.getElementById("etv").value
|
self.translation.translation = document.getElementById("etv").value
|
||||||
# This could be dangerous if generic_list_getter is getting data from any other list as well.
|
# This could be dangerous if double_list_getter is getting data from any other list as well.
|
||||||
self.translation.explanationList = common_accessors.generic_list_getter()
|
explanations = common_accessors.double_list_getter('value', 'language', True)
|
||||||
|
self.translation.explanationList = []
|
||||||
|
for entry in explanations:
|
||||||
|
explanation = Explanation()
|
||||||
|
explanation.value = entry.value
|
||||||
|
explanation.language = entry.language
|
||||||
|
self.translation.explanationList.append(explanation)
|
||||||
# common_accessors.label_list_getter()
|
# common_accessors.label_list_getter()
|
||||||
self.translation.tags = common_accessors.label_list_getter()
|
self.translation.tags = common_accessors.label_list_getter()
|
||||||
|
|
||||||
|
|
|
@ -2,3 +2,4 @@ from model.model import Model
|
||||||
from model.sense import Sense
|
from model.sense import Sense
|
||||||
from model.translation import Translation
|
from model.translation import Translation
|
||||||
from model.example import Example
|
from model.example import Example
|
||||||
|
from model.explanation import Explanation
|
||||||
|
|
|
@ -14,6 +14,7 @@ class Entry(Data):
|
||||||
self.headword = ""
|
self.headword = ""
|
||||||
self.homonymy = []
|
self.homonymy = []
|
||||||
self.headword_type = None
|
self.headword_type = None
|
||||||
|
self.headword_audio = None
|
||||||
self.grammar = ""
|
self.grammar = ""
|
||||||
self.comment = ""
|
self.comment = ""
|
||||||
self.variants = []
|
self.variants = []
|
||||||
|
@ -22,16 +23,20 @@ class Entry(Data):
|
||||||
self.measure = {}
|
self.measure = {}
|
||||||
self.labels = []
|
self.labels = []
|
||||||
self.senses = []
|
self.senses = []
|
||||||
|
self.original_xml = None
|
||||||
|
|
||||||
def import_xml(self, entry_xml):
|
def import_xml(self, entry_xml):
|
||||||
|
self.original_xml = entry_xml.cloneNode(True)
|
||||||
status = entry_xml.querySelector("head status")
|
status = entry_xml.querySelector("head status")
|
||||||
|
|
||||||
headword = entry_xml.querySelector("head headword lemma")
|
headword = entry_xml.querySelector("head headword lemma")
|
||||||
|
|
||||||
grammar = entry_xml.querySelector("head grammar category")
|
grammar = entry_xml.querySelector("head grammar category")
|
||||||
comment = entry_xml.querySelector("head comment")
|
comment = entry_xml.querySelector("head comment")
|
||||||
self.status = status.textContent if status else ""
|
self.status = status.textContent if status else ""
|
||||||
self.headword = headword.textContent if headword else ""
|
self.headword = headword.textContent if headword else ""
|
||||||
self.headword_type = headword.getAttribute("type") if headword else None
|
self.headword_type = headword.getAttribute("type") if headword and headword.hasAttribute("type") else None
|
||||||
|
self.headword_audio = headword.getAttribute("audio") if headword and headword.hasAttribute("audio") else None
|
||||||
self.grammar = grammar.textContent if grammar else ""
|
self.grammar = grammar.textContent if grammar else ""
|
||||||
self.comment = comment.textContent if comment else ""
|
self.comment = comment.textContent if comment else ""
|
||||||
self.variants = [v.textContent for v in entry_xml.querySelectorAll("head variantList variant")]
|
self.variants = [v.textContent for v in entry_xml.querySelectorAll("head variantList variant")]
|
||||||
|
|
|
@ -40,7 +40,7 @@ class Example(Data):
|
||||||
return example
|
return example
|
||||||
|
|
||||||
def import_xml(self, example_xml):
|
def import_xml(self, example_xml):
|
||||||
self.translations = from_container_list(example_xml.querySelectorAll("translationContainer"))
|
self.translations = from_container_list(example_xml.querySelectorAll("translationContainerList translationContainer"))
|
||||||
|
|
||||||
if example_xml.hasAttribute("modified"):
|
if example_xml.hasAttribute("modified"):
|
||||||
self.edited = example_xml.getAttribute("modified") == "true"
|
self.edited = example_xml.getAttribute("modified") == "true"
|
||||||
|
|
21
src/model/explanation.py
Normal file
21
src/model/explanation.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
from model.data import Data
|
||||||
|
|
||||||
|
from lib.snabbdom import h
|
||||||
|
|
||||||
|
|
||||||
|
class Explanation(Data):
|
||||||
|
def __init__(self):
|
||||||
|
self.value = ""
|
||||||
|
self.language = ""
|
||||||
|
|
||||||
|
def import_dom(self, explanation_dom):
|
||||||
|
|
||||||
|
self.value = explanation_dom.textContent if explanation_dom else ""
|
||||||
|
self.language = explanation_dom.getAttribute("language") if explanation_dom.hasAttribute("language") else ""
|
||||||
|
|
||||||
|
def export(self, doc):
|
||||||
|
result = doc.createElement("explanation")
|
||||||
|
result.textContent = self.value
|
||||||
|
if self.language != "": result.setAttribute('language', self.language)
|
||||||
|
|
||||||
|
return result
|
|
@ -18,14 +18,14 @@ class Sense(Data):
|
||||||
|
|
||||||
def import_xml(self, sense_xml, idx):
|
def import_xml(self, sense_xml, idx):
|
||||||
self.original_idx = idx
|
self.original_idx = idx
|
||||||
|
|
||||||
for definition in sense_xml.querySelectorAll("definitionList definition"):
|
for definition in sense_xml.querySelectorAll("definitionList definition"):
|
||||||
key = definition.getAttribute("type")
|
key = definition.getAttribute("type")
|
||||||
self.definition[key] = definition.textContent
|
self.definition[key] = definition.textContent
|
||||||
|
|
||||||
self.labels = import_label_list("sense > labelList label", sense_xml)
|
self.labels = import_label_list("sense > labelList label", sense_xml)
|
||||||
self.translations = from_container_list(
|
self.translations = from_container_list(
|
||||||
sense_xml.querySelectorAll("translationContainerList translationContainer"))
|
sense_xml.querySelectorAll('sense > translationContainerList translationContainer'))
|
||||||
|
|
||||||
for example_xml in sense_xml.querySelectorAll("exampleContainerList exampleContainer"):
|
for example_xml in sense_xml.querySelectorAll("exampleContainerList exampleContainer"):
|
||||||
example = Example()
|
example = Example()
|
||||||
example.import_xml(example_xml)
|
example.import_xml(example_xml)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from model.tags import import_label_list
|
from model.tags import import_label_list
|
||||||
|
from model.explanation import Explanation
|
||||||
from model.data import Data
|
from model.data import Data
|
||||||
|
|
||||||
from lib.snabbdom import h
|
from lib.snabbdom import h
|
||||||
|
@ -32,8 +33,8 @@ class Translation(Data):
|
||||||
self.translation = ""
|
self.translation = ""
|
||||||
self.source = ""
|
self.source = ""
|
||||||
self.targetLang = ""
|
self.targetLang = ""
|
||||||
self.explanation = ""
|
self.audio = ""
|
||||||
self.explanationList = []
|
self.explanationList = set()
|
||||||
self.tags = []
|
self.tags = []
|
||||||
|
|
||||||
def import_xml(self, translation_xml):
|
def import_xml(self, translation_xml):
|
||||||
|
@ -43,14 +44,14 @@ class Translation(Data):
|
||||||
self.translation = translation.textContent
|
self.translation = translation.textContent
|
||||||
self.source = translation.getAttribute("source") if translation.hasAttribute("source") else ""
|
self.source = translation.getAttribute("source") if translation.hasAttribute("source") else ""
|
||||||
self.targetLang = translation.getAttribute("targetLang") if translation.hasAttribute("targetLang") else ""
|
self.targetLang = translation.getAttribute("targetLang") if translation.hasAttribute("targetLang") else ""
|
||||||
|
self.audio = translation.getAttribute("audio") if translation.hasAttribute("audio") else ""
|
||||||
|
|
||||||
explanationList = translation_xml.querySelectorAll("explanationList explanation")
|
explanationList = translation_xml.querySelectorAll("explanationList explanation")
|
||||||
|
for explanation_dom in explanationList:
|
||||||
|
explanation = Explanation()
|
||||||
|
explanation.import_dom(explanation_dom)
|
||||||
|
self.explanationList.append(explanation)
|
||||||
|
|
||||||
for explanation in explanationList:
|
|
||||||
self.explanationList.append(explanation.textContent if explanation else "")
|
|
||||||
|
|
||||||
explanation = translation_xml.querySelector("explanation")
|
|
||||||
self.explanation = explanation.textContent if explanation else ""
|
|
||||||
self.tags = import_label_list("labelList label", translation_xml)
|
self.tags = import_label_list("labelList label", translation_xml)
|
||||||
|
|
||||||
def view(self, model):
|
def view(self, model):
|
||||||
|
@ -66,10 +67,10 @@ class Translation(Data):
|
||||||
if self.source:
|
if self.source:
|
||||||
elements.append(h("span.translation-source", {}, self.source))
|
elements.append(h("span.translation-source", {}, self.source))
|
||||||
|
|
||||||
explanation_class = ".translation-explanation" if self.translation else ""
|
if (self.explanationList):
|
||||||
|
explanation_class = ".explanations" if self.translation else ".explanations.solo"
|
||||||
# elements.append(h("span{}".format(explanation_class), {}, self.explanations))
|
explanations = [explanation.value for explanation in self.explanationList]
|
||||||
elements.append(h("span{}".format(explanation_class), {}, ", ".join(self.explanationList)))
|
elements.append(h("span{}".format(explanation_class), {}, ", ".join(explanations)))
|
||||||
|
|
||||||
return h("div.translation-div", {"on": {"click": M.msg(M.ShowTranslationMenu, self) }}, elements)
|
return h("div.translation-div", {"on": {"click": M.msg(M.ShowTranslationMenu, self) }}, elements)
|
||||||
|
|
||||||
|
@ -80,6 +81,6 @@ class Translation(Data):
|
||||||
# next two are not checked as the also can not be deleted via gui
|
# next two are not checked as the also can not be deleted via gui
|
||||||
# result = result and self.source == ""
|
# result = result and self.source == ""
|
||||||
# result = result and self.targetLang == ""
|
# result = result and self.targetLang == ""
|
||||||
result = result and self.explanation == ""
|
result = result and len(self.explanationList) == 0
|
||||||
result = result and len(self.tags) == 0
|
result = result and len(self.tags) == 0
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -49,7 +49,7 @@ def generic_list_editor(title, element_list_getter):
|
||||||
|
|
||||||
def homonymy_editor(title, current_labels):
|
def homonymy_editor(title, current_labels):
|
||||||
def split_line2(left, right):
|
def split_line2(left, right):
|
||||||
cls = "flex.two{}".format(".label-list-row")
|
cls = "flex.two{}".format(".double-list-row")
|
||||||
return h("div.{}".format(cls), {}, [
|
return h("div.{}".format(cls), {}, [
|
||||||
h("div.half", {}, left), h("div.half", {}, right)])
|
h("div.half", {}, left), h("div.half", {}, right)])
|
||||||
|
|
||||||
|
@ -67,6 +67,28 @@ def homonymy_editor(title, current_labels):
|
||||||
|
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
def explanation_editor(title, current_labels):
|
||||||
|
def split_line2(left, right):
|
||||||
|
cls = "flex.two{}".format(".double-list-row")
|
||||||
|
return h("div.{}".format(cls), {}, [
|
||||||
|
h("div.four-fifth", {}, left), h("div.fifth", {}, right)])
|
||||||
|
|
||||||
|
content = [h("p", {}, title)]
|
||||||
|
for i, explanation in enumerate(current_labels()):
|
||||||
|
language = []
|
||||||
|
value = []
|
||||||
|
language.append(h("label", {"attrs": {"for": i}}, "Language:"))
|
||||||
|
language.append(h("input.language-input", {"props": {"type": "text", "value": explanation["language"], "id": i}}, ""))
|
||||||
|
value.append(h("label", {"attrs": {"for": i + "-value"}}, "Value:"))
|
||||||
|
value.append(h("input.value-input", {"props": {"type": "text", "value": explanation["value"], "id": i + "-value"}}, ""))
|
||||||
|
|
||||||
|
content.append(split_line2(value, language))
|
||||||
|
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, current_labels)}}, "+"))
|
||||||
|
|
||||||
|
return content
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def label_list_editor(current_labels, add_label_message_class):
|
def label_list_editor(current_labels, add_label_message_class):
|
||||||
def split_line3(left, center, right, is_llr=True):
|
def split_line3(left, center, right, is_llr=True):
|
||||||
cls = "flex.three{}".format(".label-list-row" if is_llr else "")
|
cls = "flex.three{}".format(".label-list-row" if is_llr else "")
|
||||||
|
|
|
@ -21,7 +21,7 @@ def edit_translation(translation, parent, cluster_idx, num_clusters, cls):
|
||||||
content.extend([
|
content.extend([
|
||||||
split_line2("Prevedek:", h("textarea#etv", {"props": {"value": translation.translation}}, ""))])
|
split_line2("Prevedek:", h("textarea#etv", {"props": {"value": translation.translation}}, ""))])
|
||||||
|
|
||||||
content.extend(generic_list_editor("Razlage:", lambda: translation.explanationList))
|
content.extend(explanation_editor("Razlage:", lambda: translation.explanationList))
|
||||||
|
|
||||||
# cluster number
|
# cluster number
|
||||||
options = [h("option", {"props": {"selected": idx == cluster_idx}}, str(idx + 1)) for idx in range(num_clusters + 1)]
|
options = [h("option", {"props": {"selected": idx == cluster_idx}}, str(idx + 1)) for idx in range(num_clusters + 1)]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user