Compare commits
6 Commits
master
...
mt-dont-de
Author | SHA1 | Date | |
---|---|---|---|
|
45733b5cf7 | ||
|
f8bd865316 | ||
|
a26cbcf4d3 | ||
|
48a91ed67a | ||
|
e1ce093ff6 | ||
|
36cce3a86e |
220
src/export.py
220
src/export.py
|
@ -7,156 +7,197 @@ def export_to_xml(model):
|
||||||
serializer = __new__(XMLSerializer())
|
serializer = __new__(XMLSerializer())
|
||||||
return serializer.serializeToString(xml_document)
|
return serializer.serializeToString(xml_document)
|
||||||
|
|
||||||
|
|
||||||
def export_entry(entry):
|
def export_entry(entry):
|
||||||
parser = __new__(DOMParser())
|
parser = __new__(DOMParser())
|
||||||
doc = parser.parseFromString("<entry />", "text/xml")
|
doc = parser.parseFromString("<entry />", "text/xml")
|
||||||
entry_xml = doc.firstChild
|
entry_xml = doc.firstChild
|
||||||
|
|
||||||
# create head
|
# create head
|
||||||
|
head = entry.original_xml.querySelector("head")
|
||||||
|
if head is None:
|
||||||
head = doc.createElement("head")
|
head = doc.createElement("head")
|
||||||
entry_xml.appendChild(head)
|
entry.original_xml.appendChild(head)
|
||||||
|
# entry_xml.appendChild(head.cloneNode(True))
|
||||||
|
|
||||||
status = doc.createElement("status")
|
status = _original_xml_query_selector("head status", entry, doc)
|
||||||
status.textContent = entry.status
|
status.textContent = entry.status
|
||||||
head.appendChild(status)
|
# head.appendChild(status.cloneNode(True))
|
||||||
|
|
||||||
headword = doc.createElement("headword")
|
|
||||||
headword_lemma = doc.createElement("lemma")
|
|
||||||
|
|
||||||
# headword_lemma = entry.original_xml.querySelector("head headword lemma")
|
|
||||||
|
# headword = doc.createElement("headword")
|
||||||
|
# headword_lemma = doc.createElement("lemma")
|
||||||
|
|
||||||
|
headword = _original_xml_query_selector("head headword", entry, doc)
|
||||||
|
headword_lemma = _original_xml_query_selector("head headword lemma", entry, doc)
|
||||||
|
|
||||||
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:
|
if entry.headword_audio is not None:
|
||||||
headword_lemma.setAttribute("audio", entry.headword_audio)
|
headword_lemma.setAttribute("audio", entry.headword_audio)
|
||||||
headword.appendChild(headword_lemma)
|
|
||||||
head.appendChild(headword)
|
|
||||||
|
|
||||||
homonymy = doc.createElement("homonymy")
|
# headword.appendChild(headword_lemma.cloneNode(True))
|
||||||
headword.appendChild(homonymy)
|
# head.appendChild(headword.cloneNode(True))
|
||||||
|
homonymy = _original_xml_query_selector("head headword homonymy", entry, doc)
|
||||||
|
original_homonymy = entry.original_xml.querySelectorAll("head headword homonymy homonymyFeature")
|
||||||
|
|
||||||
for hFeature in entry.homonymy:
|
for hFeature in entry.homonymy:
|
||||||
feature = doc.createElement("homonymyFeature")
|
feature = doc.createElement("homonymyFeature")
|
||||||
feature.textContent = hFeature.value
|
if hFeature.id >= 0:
|
||||||
# Can't use hFeature.name, because Python has name reserver and so it becomes py_name in JS
|
feature = original_homonymy[hFeature.id]
|
||||||
feature.setAttribute("name", hFeature["name"])
|
else:
|
||||||
homonymy.appendChild(feature)
|
homonymy.appendChild(feature)
|
||||||
|
|
||||||
|
feature.textContent = hFeature.value
|
||||||
|
# Can't use hFeature.name, because Python has name reserved and so it becomes py_name in JS
|
||||||
|
feature.setAttribute("name", hFeature["name"])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# if({}) works uncorrectly in transcrypt
|
# if({}) works uncorrectly in transcrypt
|
||||||
if len(entry.lexical_unit) > 0:
|
if len(entry.lexical_unit) > 0:
|
||||||
lexunit = doc.createElement("lexicalUnit")
|
lexunit = _original_xml_query_selector("head lexicalUnit", entry, doc)
|
||||||
|
# lexunit = doc.createElement("lexicalUnit")
|
||||||
lexunit.setAttribute("id", entry.lexical_unit["id"])
|
lexunit.setAttribute("id", entry.lexical_unit["id"])
|
||||||
lexunit.setAttribute("type", "single")
|
lexunit.setAttribute("type", "single")
|
||||||
lexeme = doc.createElement("lexeme")
|
lexeme = _original_xml_query_selector("head lexicalUnit lexeme", entry, doc)
|
||||||
|
# lexeme = doc.createElement("lexeme")
|
||||||
lexeme.setAttribute("lexical_unit_lexeme_id", entry.lexical_unit["id"])
|
lexeme.setAttribute("lexical_unit_lexeme_id", entry.lexical_unit["id"])
|
||||||
lexeme.textContent = entry.lexical_unit["text"]
|
lexeme.textContent = entry.lexical_unit["text"]
|
||||||
|
|
||||||
lexunit.appendChild(lexeme)
|
# lexunit.appendChild(lexeme.cloneNode(True))
|
||||||
head.appendChild(lexunit)
|
# head.appendChild(lexunit.cloneNode(True))
|
||||||
|
|
||||||
# Example of keeping original xml and adding changes to it only
|
# Example of keeping original xml and adding changes to it only
|
||||||
grammar_category = entry.original_xml.querySelector("head grammar category")
|
grammar = _original_xml_query_selector("head grammar", entry, doc)
|
||||||
if grammar_category is None:
|
grammar_category = _original_xml_query_selector("head grammar category", entry, doc)
|
||||||
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
|
||||||
|
|
||||||
head.appendChild(entry.original_xml.querySelector("head grammar"))
|
# head.appendChild(grammar.cloneNode(True))
|
||||||
|
console.log(entry.original_xml)
|
||||||
|
|
||||||
if len(entry.measure) > 0:
|
if len(entry.measure) > 0:
|
||||||
measure_list = doc.createElement("measureList")
|
measure_list = _original_xml_query_selector("head measureList", entry, doc)
|
||||||
measure = doc.createElement("measure")
|
measure = _original_xml_query_selector("head measureList measure", entry, doc)
|
||||||
|
|
||||||
|
# measure_list = doc.createElement("measureList")
|
||||||
|
# measure = doc.createElement("measure")
|
||||||
measure.setAttribute("source", entry.measure["source"])
|
measure.setAttribute("source", entry.measure["source"])
|
||||||
measure.setAttribute("type", entry.measure["type"])
|
measure.setAttribute("type", entry.measure["type"])
|
||||||
measure.textContent = entry.measure["text"]
|
measure.textContent = entry.measure["text"]
|
||||||
|
|
||||||
measure_list.appendChild(measure)
|
# head.appendChild(measure_list)
|
||||||
head.appendChild(measure_list)
|
|
||||||
|
|
||||||
variants = doc.createElement("variantList")
|
|
||||||
head.appendChild(variants)
|
|
||||||
|
|
||||||
|
# Same problem as homonymy
|
||||||
|
variants = _original_xml_query_selector("head variantList", entry, doc)
|
||||||
|
og_variants = entry.original_xml.querySelectorAll("head variantList variant")
|
||||||
for v in entry.variants:
|
for v in entry.variants:
|
||||||
variant = doc.createElement("variant")
|
variant = doc.createElement("variant")
|
||||||
variant.textContent = v
|
if v.id >= 0:
|
||||||
|
variant = og_variants[v.id]
|
||||||
|
else:
|
||||||
variants.appendChild(variant)
|
variants.appendChild(variant)
|
||||||
|
|
||||||
relist = doc.createElement("relatedEntryList")
|
variant.textContent = v.value
|
||||||
head.appendChild(relist)
|
|
||||||
|
|
||||||
|
# relist = _original_xml_query_selector("head relatedEntryList", entry, doc)
|
||||||
|
# relist = doc.createElement("relatedEntryList")
|
||||||
|
relist = _original_xml_query_selector("head relatedEntryList", entry, doc)
|
||||||
|
og_relist = entry.original_xml.querySelectorAll("head relatedEntryList relatedEntry")
|
||||||
|
# head.appendChild(relist.cloneNode(True))
|
||||||
for re in entry.related_entries:
|
for re in entry.related_entries:
|
||||||
relateEntry = doc.createElement("relatedEntry")
|
relateEntry = doc.createElement("relatedEntry")
|
||||||
relateEntry.textContent = re
|
|
||||||
|
if re.id >= 0:
|
||||||
|
relateEntry = og_relist[re.id]
|
||||||
|
else:
|
||||||
relist.appendChild(relateEntry)
|
relist.appendChild(relateEntry)
|
||||||
|
|
||||||
head.appendChild(_export_label_list(doc, entry.labels))
|
relateEntry.textContent = re.value
|
||||||
|
_export_label_list(doc, entry.labels, head)
|
||||||
|
|
||||||
comment = doc.createElement("comment")
|
# comment = doc.createElement("comment")
|
||||||
|
comment = _original_xml_query_selector("head comment", entry, doc)
|
||||||
comment.textContent = entry.comment
|
comment.textContent = entry.comment
|
||||||
head.appendChild(comment)
|
# head.appendChild(comment.cloneNode(True))
|
||||||
|
|
||||||
# now lets do body
|
# now lets do body
|
||||||
|
|
||||||
|
body = entry.original_xml.querySelector("body")
|
||||||
|
if body is None:
|
||||||
body = doc.createElement("body")
|
body = doc.createElement("body")
|
||||||
entry_xml.appendChild(body)
|
entry.original_xml.appendChild(body)
|
||||||
|
# entry_xml.appendChild(body)
|
||||||
sense_list = doc.createElement("senseList")
|
|
||||||
body.appendChild(sense_list)
|
|
||||||
|
|
||||||
|
# sense_list = doc.createElement("senseList")
|
||||||
|
sense_list = _original_xml_query_selector("body senseList", entry, doc)
|
||||||
for sense in entry.senses:
|
for sense in entry.senses:
|
||||||
sense_list.appendChild(export_sense(doc, sense))
|
|
||||||
|
|
||||||
return doc
|
|
||||||
|
|
||||||
|
|
||||||
def export_sense(doc, sense):
|
|
||||||
sense_xml = doc.createElement("sense")
|
sense_xml = doc.createElement("sense")
|
||||||
sense_xml.appendChild(_export_label_list(doc, sense.labels))
|
|
||||||
|
|
||||||
|
if sense.original_xml is not None:
|
||||||
|
sense_xml = sense.original_xml
|
||||||
|
|
||||||
|
sense_list.appendChild(sense_xml)
|
||||||
|
export_sense(doc, sense, sense_xml)
|
||||||
|
|
||||||
|
return entry.original_xml
|
||||||
|
|
||||||
|
|
||||||
|
def export_sense(doc, sense, sense_xml):
|
||||||
|
_export_label_list(doc, sense.labels, sense_xml)
|
||||||
|
|
||||||
|
definition_list = sense_xml.querySelector("definitionList")
|
||||||
|
if definition_list is None:
|
||||||
definition_list = doc.createElement("definitionList")
|
definition_list = doc.createElement("definitionList")
|
||||||
sense_xml.appendChild(definition_list)
|
sense_xml.appendChild(definition_list)
|
||||||
|
|
||||||
for typ, text in sense.definition.items():
|
for definition in sense.definitions:
|
||||||
definition = doc.createElement("definition")
|
definition_xml = definition.original_xml if definition.original_xml != None else doc.createElement("definition")
|
||||||
definition.textContent = text
|
definition_list.appendChild(definition_xml)
|
||||||
definition.setAttribute("type", typ)
|
definition_xml.textContent = definition.value
|
||||||
definition_list.appendChild(definition)
|
definition_xml.setAttribute("type", definition.type)
|
||||||
|
|
||||||
|
translation_container_list = sense_xml.querySelector("sense > translationContainerList")
|
||||||
|
if translation_container_list is None:
|
||||||
translation_container_list = doc.createElement("translationContainerList")
|
translation_container_list = doc.createElement("translationContainerList")
|
||||||
export_translation_list(doc, sense, translation_container_list)
|
|
||||||
sense_xml.appendChild(translation_container_list)
|
sense_xml.appendChild(translation_container_list)
|
||||||
|
export_translation_list(doc, sense, translation_container_list)
|
||||||
|
|
||||||
|
example_container_list = sense_xml.querySelector("sense > exampleContainerList")
|
||||||
|
if example_container_list is None:
|
||||||
example_container_list = doc.createElement("exampleContainerList")
|
example_container_list = doc.createElement("exampleContainerList")
|
||||||
sense_xml.appendChild(example_container_list)
|
sense_xml.appendChild(example_container_list)
|
||||||
|
|
||||||
for example in sense.examples:
|
for example in sense.examples:
|
||||||
example_container = example.export(doc)
|
example_container = example.export(doc, example_container_list)
|
||||||
translation_container_list = doc.createElement("translationContainerList")
|
|
||||||
export_translation_list(doc, example, translation_container_list)
|
translation_container_list = example_container.querySelector("exampleContainer > translationContainerList")
|
||||||
example_container.appendChild(translation_container_list)
|
if translation_container_list is None:
|
||||||
example_container_list.appendChild(example_container)
|
translation_container_list = doc.createElement("translationContainerList")
|
||||||
|
example_container.appendChild(translation_container_list)
|
||||||
|
|
||||||
|
export_translation_list(doc, example, translation_container_list)
|
||||||
|
|
||||||
return sense_xml
|
|
||||||
|
|
||||||
def export_translation_list(doc, py_parent, xml_parent):
|
def export_translation_list(doc, py_parent, xml_parent):
|
||||||
for cidx, cluster in enumerate(py_parent.translations):
|
for cidx, cluster in enumerate(py_parent.translations):
|
||||||
for translation in cluster:
|
for translation in cluster:
|
||||||
translation_container = export_translation(doc, translation)
|
translation_container = export_translation(doc, translation, xml_parent)
|
||||||
translation_container.setAttribute("cluster", str(cidx + 1))
|
translation_container.setAttribute("cluster", str(cidx + 1))
|
||||||
xml_parent.appendChild(translation_container)
|
# xml_parent.appendChild(translation_container)
|
||||||
|
|
||||||
|
|
||||||
def export_translation(doc, translation):
|
def export_translation(doc, translation, xml_parent):
|
||||||
translation_xml = doc.createElement("translationContainer")
|
translation_xml = translation.original_xml if translation.original_xml != None else doc.createElement("translationContainer")
|
||||||
translation_xml.appendChild(_export_label_list(doc, translation.tags))
|
xml_parent.appendChild(translation_xml)
|
||||||
|
_export_label_list(doc, translation.tags, translation_xml)
|
||||||
|
|
||||||
|
console.log(translation)
|
||||||
|
actual_t = translation.original_xml.querySelector("translation") if translation.original_xml != None else doc.createElement("translation")
|
||||||
|
if translation.original_xml is None:
|
||||||
|
translation_xml.appendChild(actual_t)
|
||||||
|
|
||||||
actual_t = doc.createElement("translation")
|
|
||||||
actual_t.textContent = translation.translation
|
actual_t.textContent = translation.translation
|
||||||
actual_t.setAttribute("targetLang", translation.targetLang)
|
actual_t.setAttribute("targetLang", translation.targetLang)
|
||||||
|
|
||||||
|
@ -165,30 +206,43 @@ def export_translation(doc, translation):
|
||||||
|
|
||||||
if translation.source:
|
if translation.source:
|
||||||
actual_t.setAttribute("source", translation.source)
|
actual_t.setAttribute("source", translation.source)
|
||||||
translation_xml.appendChild(actual_t)
|
|
||||||
|
|
||||||
if len(translation.explanationList) > 0 :
|
if len(translation.explanationList) > 0 :
|
||||||
explanationList = _export_explanation_list(doc, translation.explanationList)
|
_export_explanation_list(doc, translation.explanationList, translation_xml)
|
||||||
translation_xml.appendChild(explanationList)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return translation_xml
|
return translation_xml
|
||||||
|
|
||||||
def _export_explanation_list(doc, lst):
|
def _export_explanation_list(doc, lst, xml_parent):
|
||||||
result = doc.createElement('explanationList')
|
result = xml_parent.querySelector("explanationList")
|
||||||
|
if result is None:
|
||||||
|
result = doc.createElement("explanationList")
|
||||||
|
xml_parent.appendChild(result)
|
||||||
|
|
||||||
for explanation in lst:
|
for explanation in lst:
|
||||||
result.appendChild(explanation.export(doc))
|
result.appendChild(explanation.export(doc))
|
||||||
|
|
||||||
return result
|
def _export_label_list(doc, lst, xml_parent):
|
||||||
|
result = xml_parent.querySelector("labelList")
|
||||||
def _export_label_list(doc, lst):
|
if result is None:
|
||||||
result = doc.createElement("labelList")
|
result = doc.createElement("labelList")
|
||||||
for key, value in lst:
|
xml_parent.appendChild(result)
|
||||||
key, value = export_tag(key, value)
|
|
||||||
|
|
||||||
|
for key, value, idx in lst:
|
||||||
|
|
||||||
|
key, value = export_tag(key, value)
|
||||||
label_el = doc.createElement("label")
|
label_el = doc.createElement("label")
|
||||||
|
if idx >= 0:
|
||||||
|
label_el = result.querySelectorAll("label")[idx]
|
||||||
|
else:
|
||||||
|
result.appendChild(label_el)
|
||||||
|
|
||||||
label_el.textContent = value
|
label_el.textContent = value
|
||||||
label_el.setAttribute('type', key)
|
label_el.setAttribute('type', key)
|
||||||
result.appendChild(label_el)
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def _original_xml_query_selector(selector, entry, doc, parent_selector = selector.rsplit(' ', 1)[0]):
|
||||||
|
query = entry.original_xml.querySelector(selector)
|
||||||
|
if query is None:
|
||||||
|
query = doc.createElement(selector.rsplit(' ', 1)[1])
|
||||||
|
entry.original_xml.querySelector(parent_selector).appendChild(query)
|
||||||
|
return query
|
||||||
|
|
|
@ -4,8 +4,10 @@ from browser import document
|
||||||
def generic_list_getter():
|
def generic_list_getter():
|
||||||
result = []
|
result = []
|
||||||
for input_el in document.getElementsByClassName("list-adder-input"):
|
for input_el in document.getElementsByClassName("list-adder-input"):
|
||||||
result_candidate = input_el.value
|
result_candidate = {"value": input_el.value}
|
||||||
if result_candidate != "":
|
if input_el.hasAttribute("data-id"):
|
||||||
|
result_candidate.id = int(input_el.getAttribute("data-id"))
|
||||||
|
if result_candidate.value != "":
|
||||||
result.append(result_candidate)
|
result.append(result_candidate)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -13,16 +15,19 @@ def generic_list_getter():
|
||||||
def double_list_getter(firstParameter, secondParameter, allowEmptyField = False):
|
def double_list_getter(firstParameter, secondParameter, allowEmptyField = False):
|
||||||
result = []
|
result = []
|
||||||
for row in document.getElementsByClassName("double-list-row"):
|
for row in document.getElementsByClassName("double-list-row"):
|
||||||
firstValue = row.querySelector("." + firstParameter + "-input").value
|
output = {}
|
||||||
secondValue = row.querySelector("." + secondParameter + "-input").value
|
output[firstParameter] = row.querySelector("." + firstParameter + "-input").value
|
||||||
|
output[secondParameter] = row.querySelector("." + secondParameter + "-input").value
|
||||||
|
if row.hasAttribute("data-id"):
|
||||||
|
output.id = int(row.getAttribute("data-id"))
|
||||||
|
|
||||||
if (allowEmptyField is False and '' in [firstValue, secondValue]):
|
if (allowEmptyField is False and '' in [output[firstParameter], output[secondParameter]]):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if (allowEmptyField is True and all('' == value or value.isspace() for value in [firstValue, secondValue])):
|
if (allowEmptyField is True and all('' == value or value.isspace() for value in [output[firstParameter], output[secondParameter]])):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
result.append({firstParameter: firstValue, secondParameter: secondValue})
|
result.append(output)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -33,6 +38,7 @@ def label_list_getter():
|
||||||
ltype = row.querySelector(".label-type")
|
ltype = row.querySelector(".label-type")
|
||||||
lvalue = row.querySelector(".label-value")
|
lvalue = row.querySelector(".label-value")
|
||||||
lother = row.querySelector(".label-value-other")
|
lother = row.querySelector(".label-value-other")
|
||||||
|
idx = int(row.getAttribute("data-id")) if row.hasAttribute("data-id") else -1
|
||||||
|
|
||||||
if lother is None:
|
if lother is None:
|
||||||
continue
|
continue
|
||||||
|
@ -44,7 +50,7 @@ def label_list_getter():
|
||||||
if not value:
|
if not value:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
result.append((ltype.textContent, value))
|
result.append((ltype.textContent, value, idx))
|
||||||
|
|
||||||
kontrastivno = document.getElementById("kontrastivno-input").checked;
|
kontrastivno = document.getElementById("kontrastivno-input").checked;
|
||||||
if kontrastivno:
|
if kontrastivno:
|
||||||
|
|
|
@ -21,7 +21,9 @@ class DeleteRelatedEntries(DeleteVariants):
|
||||||
|
|
||||||
class DeleteHomonymy(NoReset):
|
class DeleteHomonymy(NoReset):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
for el in document.getElementsByClassName("list-adder-input"):
|
for el in document.getElementsByClassName("name-input"):
|
||||||
|
el.value = ""
|
||||||
|
for el in document.getElementsByClassName("value-input"):
|
||||||
el.value = ""
|
el.value = ""
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ class EditExampleText(Message):
|
||||||
if example.newly_created:
|
if example.newly_created:
|
||||||
example.newly_created = False
|
example.newly_created = False
|
||||||
sense.examples.append(example)
|
sense.examples.append(example)
|
||||||
|
console.log(example)
|
||||||
idx = 0
|
idx = 0
|
||||||
for txt in document.getElementsByClassName("example-component-text"):
|
for txt in document.getElementsByClassName("example-component-text"):
|
||||||
example.components[idx].text = txt.value
|
example.components[idx].text = txt.value
|
||||||
|
|
|
@ -18,10 +18,15 @@ class SenseMoveUp(DataChgClickMessage):
|
||||||
assert(sidx >= 0)
|
assert(sidx >= 0)
|
||||||
if sidx == 0:
|
if sidx == 0:
|
||||||
return
|
return
|
||||||
|
# if sense.original_idx >= 0:
|
||||||
|
# if model.entry.senses[sidx - 1].original_idx >= 0:
|
||||||
|
# original_parent = model.entry.original_xml.querySelector("body senseList")
|
||||||
|
# original_parent.insertBefore(original_parent.children[sidx], original_parent.children[sidx - 1])
|
||||||
|
# model.entry.senses[sidx].original_idx, model.entry.senses[sidx - 1].original_idx = model.entry.senses[sidx - 1].original_idx, model.entry.senses[sidx].original_idx
|
||||||
|
# else:
|
||||||
|
|
||||||
model.entry.senses[sidx], model.entry.senses[sidx - 1] = model.entry.senses[sidx - 1], model.entry.senses[sidx]
|
model.entry.senses[sidx], model.entry.senses[sidx - 1] = model.entry.senses[sidx - 1], model.entry.senses[sidx]
|
||||||
|
|
||||||
|
|
||||||
class SenseMoveDown(DataChgClickMessage):
|
class SenseMoveDown(DataChgClickMessage):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
sense = self.get_arg(0, Sense)
|
sense = self.get_arg(0, Sense)
|
||||||
|
@ -30,7 +35,10 @@ class SenseMoveDown(DataChgClickMessage):
|
||||||
assert(sidx >= 0)
|
assert(sidx >= 0)
|
||||||
if sidx == len(model.senses) - 1:
|
if sidx == len(model.senses) - 1:
|
||||||
return
|
return
|
||||||
|
# if sense.original_idx >= 0 and model.entry.senses[sidx + 1].original_idx >= 0:
|
||||||
|
# original_parent = model.entry.original_xml.querySelector("body senseList")
|
||||||
|
# original_parent.insertBefore(original_parent.children[sidx + 1], original_parent.children[sidx])
|
||||||
|
# model.entry.senses[sidx].original_idx, model.entry.senses[sidx + 1].original_idx = model.entry.senses[sidx + 1].original_idx, model.entry.senses[sidx].original_idx
|
||||||
model.entry.senses[sidx], model.entry.senses[sidx + 1] = model.entry.senses[sidx + 1], model.entry.senses[sidx]
|
model.entry.senses[sidx], model.entry.senses[sidx + 1] = model.entry.senses[sidx + 1], model.entry.senses[sidx]
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,6 +50,12 @@ class SenseBin(DataChgClickMessage):
|
||||||
assert(sidx >= 0)
|
assert(sidx >= 0)
|
||||||
model.entry.senses.splice(sidx, 1)
|
model.entry.senses.splice(sidx, 1)
|
||||||
|
|
||||||
|
# if sense.original_idx >= 0:
|
||||||
|
# model.entry.original_xml.querySelectorAll("body senseList sense")[sense.original_idx].remove()
|
||||||
|
# for index, sense in enumerate(model.entry.senses):
|
||||||
|
# if (sense.original_idx >= 0):
|
||||||
|
# sense.original_idx = index
|
||||||
|
|
||||||
|
|
||||||
class AddMultiwordExample(DataChgClickMessage):
|
class AddMultiwordExample(DataChgClickMessage):
|
||||||
def on_event(self, event):
|
def on_event(self, event):
|
||||||
|
|
|
@ -17,6 +17,14 @@ class EditSenseLabel(Message):
|
||||||
sense = self.get_arg(0, Sense)
|
sense = self.get_arg(0, Sense)
|
||||||
sense.labels = common_accessors.label_list_getter()
|
sense.labels = common_accessors.label_list_getter()
|
||||||
|
|
||||||
|
keptIds = [entry[2] for entry in sense.labels]
|
||||||
|
for index, entry in enumerate(sense.original_xml.querySelectorAll("labelList label")):
|
||||||
|
if (index not in keptIds):
|
||||||
|
entry.remove()
|
||||||
|
|
||||||
|
for index, entry in enumerate(sense.labels):
|
||||||
|
if (entry[2] >= 0):
|
||||||
|
entry[2] = index
|
||||||
|
|
||||||
class AddToGenericList(NoReset):
|
class AddToGenericList(NoReset):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
|
@ -43,14 +51,14 @@ class AddToLabelList(NoReset):
|
||||||
class AddSense(Message):
|
class AddSense(Message):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
sense = Sense()
|
sense = Sense()
|
||||||
sense.definition = {"indicator": "New Sense"}
|
sense.definitions.append({"type": "indicator", "value": "New Sense"})
|
||||||
model.entry.senses.append(sense)
|
model.entry.senses.append(sense)
|
||||||
|
|
||||||
|
|
||||||
class EditSenseDefinition(QuestionMessage):
|
class EditSenseDefinition(QuestionMessage):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
sense = self.get_arg(0, Sense)
|
sense = self.get_arg(0, Sense)
|
||||||
sense.definition["indicator"] = self.new_text
|
sense.definitions[0].value = self.new_text
|
||||||
|
|
||||||
|
|
||||||
class EditComment(QuestionMessage):
|
class EditComment(QuestionMessage):
|
||||||
|
@ -86,23 +94,36 @@ class DoChosenExamples(Message):
|
||||||
class EditVariants(Message):
|
class EditVariants(Message):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
variants = common_accessors.generic_list_getter()
|
variants = common_accessors.generic_list_getter()
|
||||||
|
update_entries(variants, "head variantList variant", model)
|
||||||
model.entry.variants = variants
|
model.entry.variants = variants
|
||||||
|
|
||||||
class EditHomonymy(Message):
|
class EditHomonymy(Message):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
homonymy = common_accessors.double_list_getter("value", "name")
|
homonymy = common_accessors.double_list_getter("value", "name")
|
||||||
|
|
||||||
|
update_entries(homonymy, "head headword homonymy homonymyFeature", model)
|
||||||
|
|
||||||
model.entry.homonymy = homonymy
|
model.entry.homonymy = homonymy
|
||||||
|
|
||||||
|
|
||||||
class EditRelatedEntries(Message):
|
class EditRelatedEntries(Message):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
related_entries = common_accessors.generic_list_getter()
|
related_entries = common_accessors.generic_list_getter()
|
||||||
|
update_entries(related_entries, "head relatedEntryList relatedEntry", model)
|
||||||
model.entry.related_entries = related_entries
|
model.entry.related_entries = related_entries
|
||||||
|
|
||||||
|
|
||||||
class EditEntryLabels(Message):
|
class EditEntryLabels(Message):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
labels = common_accessors.label_list_getter()
|
labels = common_accessors.label_list_getter()
|
||||||
|
keptIds = [entry[2] for entry in labels]
|
||||||
|
for index, entry in enumerate(model.entry.original_xml.querySelectorAll("labelList label")):
|
||||||
|
if (index not in keptIds):
|
||||||
|
entry.remove()
|
||||||
|
|
||||||
|
for index, entry in enumerate(labels):
|
||||||
|
if (entry[2] >= 0):
|
||||||
|
entry[2] = index
|
||||||
model.entry.labels = labels
|
model.entry.labels = labels
|
||||||
|
|
||||||
|
|
||||||
|
@ -118,3 +139,13 @@ class ExampleClusterAdd(DataChgClickMessage):
|
||||||
example = self.get_arg(0, Example)
|
example = self.get_arg(0, Example)
|
||||||
example.set_cluster(ExampleClusters.first_empty_cluster())
|
example.set_cluster(ExampleClusters.first_empty_cluster())
|
||||||
|
|
||||||
|
|
||||||
|
def update_entries(updated_list, query, model):
|
||||||
|
keptIds = [entry.id for entry in updated_list]
|
||||||
|
for index, entry in enumerate(model.entry.original_xml.querySelectorAll(query)):
|
||||||
|
if (index not in keptIds):
|
||||||
|
entry.remove()
|
||||||
|
|
||||||
|
for index, entry in enumerate(updated_list):
|
||||||
|
if (entry.id >= 0):
|
||||||
|
entry.id = index
|
||||||
|
|
|
@ -14,6 +14,7 @@ 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 double_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.
|
||||||
explanations = common_accessors.double_list_getter('value', 'language', True)
|
explanations = common_accessors.double_list_getter('value', 'language', True)
|
||||||
self.translation.explanationList = []
|
self.translation.explanationList = []
|
||||||
|
@ -21,10 +22,19 @@ class EditTranslation(DataChgClickMessage):
|
||||||
explanation = Explanation()
|
explanation = Explanation()
|
||||||
explanation.value = entry.value
|
explanation.value = entry.value
|
||||||
explanation.language = entry.language
|
explanation.language = entry.language
|
||||||
|
explanation.original_xml = entry.original_xml if entry.original_xml != None else None
|
||||||
self.translation.explanationList.append(explanation)
|
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()
|
||||||
|
keptIds = [entry[2] for entry in self.translation.tags]
|
||||||
|
for index, entry in enumerate(self.translation.original_xml.querySelectorAll("labelList label")):
|
||||||
|
if (index not in keptIds):
|
||||||
|
entry.remove()
|
||||||
|
|
||||||
|
for index, entry in enumerate(self.translation.tags):
|
||||||
|
if (entry[2] >= 0):
|
||||||
|
entry[2] = index
|
||||||
# check if empty, remove!
|
# check if empty, remove!
|
||||||
if self.translation.is_empty():
|
if self.translation.is_empty():
|
||||||
model.entry.remove_translation(self.translation)
|
model.entry.remove_translation(self.translation)
|
||||||
|
|
|
@ -63,7 +63,7 @@ class Data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def overwrite_with_copy(self):
|
def overwrite_with_copy(self):
|
||||||
for key, value in dict(self._copy).items():
|
for key, value in dict(self).items():
|
||||||
# skip functions and _copy
|
# skip functions and _copy
|
||||||
if key == "_copy" or type(value) is None:
|
if key == "_copy" or type(value) is None:
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -26,7 +26,8 @@ class Entry(Data):
|
||||||
self.original_xml = None
|
self.original_xml = None
|
||||||
|
|
||||||
def import_xml(self, entry_xml):
|
def import_xml(self, entry_xml):
|
||||||
self.original_xml = entry_xml.cloneNode(True)
|
console.log(entry_xml)
|
||||||
|
self.original_xml = entry_xml
|
||||||
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")
|
||||||
|
@ -39,9 +40,9 @@ class Entry(Data):
|
||||||
self.headword_audio = headword.getAttribute("audio") if headword and headword.hasAttribute("audio") 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 = [{"value": v.textContent, "id": index} for index, v in enumerate(entry_xml.querySelectorAll("head variantList variant"))]
|
||||||
self.homonymy = [{"value": v.textContent, "name": v.getAttribute("name")} for v in entry_xml.querySelectorAll("head headword homonymy homonymyFeature ")]
|
self.homonymy = [{"value": v.textContent, "name": v.getAttribute("name"), "id": index} for index, v in enumerate(entry_xml.querySelectorAll("head headword homonymy homonymyFeature "))]
|
||||||
self.related_entries = [re.textContent for re in entry_xml.querySelectorAll("head relatedEntryList relatedEntry")]
|
self.related_entries = [{"value": re.textContent, "id": index} for index, re in enumerate(entry_xml.querySelectorAll("head relatedEntryList relatedEntry"))]
|
||||||
|
|
||||||
lex_unit = entry_xml.querySelector("lexical_unit lexeme,lexicalUnit lexeme")
|
lex_unit = entry_xml.querySelector("lexical_unit lexeme,lexicalUnit lexeme")
|
||||||
if lex_unit:
|
if lex_unit:
|
||||||
|
@ -54,12 +55,13 @@ class Entry(Data):
|
||||||
self.measure["type"] = measure.getAttribute("type")
|
self.measure["type"] = measure.getAttribute("type")
|
||||||
self.measure["text"] = measure.textContent
|
self.measure["text"] = measure.textContent
|
||||||
|
|
||||||
self.labels = import_label_list("head labelList label", entry_xml)
|
self.labels = import_label_list("head labelList label", self.original_xml)
|
||||||
|
|
||||||
for i, sense_xml in enumerate(entry_xml.querySelectorAll("body senseList sense")):
|
for i, sense_xml in enumerate(entry_xml.querySelectorAll("body senseList sense")):
|
||||||
sense = Sense()
|
sense = Sense()
|
||||||
sense.import_xml(sense_xml, i)
|
sense.import_xml(sense_xml, i)
|
||||||
self.senses.append(sense)
|
self.senses.append(sense)
|
||||||
|
sense_xml.remove()
|
||||||
|
|
||||||
|
|
||||||
def view(self, model):
|
def view(self, model):
|
||||||
|
@ -96,7 +98,7 @@ class Entry(Data):
|
||||||
if len(self.variants) == 0:
|
if len(self.variants) == 0:
|
||||||
view_buttons.append(buttons[0])
|
view_buttons.append(buttons[0])
|
||||||
else:
|
else:
|
||||||
view_table.append((buttons[0], ", ".join(self.variants)))
|
view_table.append((buttons[0], ", ".join(v.value for v in self.variants)))
|
||||||
|
|
||||||
if len(self.homonymy) == 0:
|
if len(self.homonymy) == 0:
|
||||||
view_buttons.append(buttons[4])
|
view_buttons.append(buttons[4])
|
||||||
|
@ -106,7 +108,7 @@ class Entry(Data):
|
||||||
if len(self.related_entries) == 0:
|
if len(self.related_entries) == 0:
|
||||||
view_buttons.append(buttons[1])
|
view_buttons.append(buttons[1])
|
||||||
else:
|
else:
|
||||||
view_table.append((buttons[1], ", ".join(self.related_entries)))
|
view_table.append((buttons[1], ", ".join(re.value for re in self.related_entries)))
|
||||||
|
|
||||||
if len(self.labels) == 0:
|
if len(self.labels) == 0:
|
||||||
view_buttons.append(buttons[2])
|
view_buttons.append(buttons[2])
|
||||||
|
@ -141,4 +143,3 @@ class Entry(Data):
|
||||||
if translation in cluster:
|
if translation in cluster:
|
||||||
cluster.remove(translation)
|
cluster.remove(translation)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,10 @@ class ComponentLexeme(Data):
|
||||||
self.text = ""
|
self.text = ""
|
||||||
self.role = ""
|
self.role = ""
|
||||||
self.no_space = False
|
self.no_space = False
|
||||||
|
self.original_xml = None
|
||||||
|
|
||||||
def import_xml(self, xml):
|
def import_xml(self, xml):
|
||||||
|
self.original_xml = xml.cloneNode(True)
|
||||||
if xml.nodeName == "#text":
|
if xml.nodeName == "#text":
|
||||||
self.text = xml.data
|
self.text = xml.data
|
||||||
self.role = None
|
self.role = None
|
||||||
|
@ -25,6 +27,7 @@ class ComponentLexeme(Data):
|
||||||
for oth_attr in ["lexeme_id", "lexical_unit_lexeme_id", "slolex", "kol", "sloleks"]:
|
for oth_attr in ["lexeme_id", "lexical_unit_lexeme_id", "slolex", "kol", "sloleks"]:
|
||||||
if xml.hasAttribute(oth_attr):
|
if xml.hasAttribute(oth_attr):
|
||||||
self.other_attributes[oth_attr] = xml.getAttribute(oth_attr)
|
self.other_attributes[oth_attr] = xml.getAttribute(oth_attr)
|
||||||
|
xml.remove()
|
||||||
|
|
||||||
def isValid(self):
|
def isValid(self):
|
||||||
return len(self.text) > 0
|
return len(self.text) > 0
|
||||||
|
@ -32,7 +35,8 @@ class ComponentLexeme(Data):
|
||||||
def export(self, doc):
|
def export(self, doc):
|
||||||
if self.role is None:
|
if self.role is None:
|
||||||
return doc.createTextNode(self.text)
|
return doc.createTextNode(self.text)
|
||||||
result = doc.createElement("comp")
|
result = self.original_xml if self.original_xml is not None else doc.createElement("comp")
|
||||||
|
|
||||||
result.setAttribute("role", self.role)
|
result.setAttribute("role", self.role)
|
||||||
result.textContent = self.text
|
result.textContent = self.text
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,17 @@ from lib.snabbdom import h
|
||||||
class CorpusExample:
|
class CorpusExample:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.other_attributes = {}
|
self.other_attributes = {}
|
||||||
|
self.original_xml = None
|
||||||
|
|
||||||
def import_xml(self, example_xml):
|
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)
|
||||||
|
self.original_xml = example_xml
|
||||||
|
example_xml.remove()
|
||||||
|
|
||||||
def export(self, doc, modified):
|
def export(self, doc, modified):
|
||||||
result = doc.createElement("corpusExample")
|
result = self.original_xml if self.original_xml is not None else doc.createElement("corpusExample")
|
||||||
if modified:
|
if modified:
|
||||||
result.setAttribute("modified", "true")
|
result.setAttribute("modified", "true")
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ from model.example_clusters import ExampleClusters
|
||||||
|
|
||||||
class Example(Data):
|
class Example(Data):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.original_xml = None
|
||||||
self.translations = []
|
self.translations = []
|
||||||
self.inner = None
|
self.inner = None
|
||||||
self.components = []
|
self.components = []
|
||||||
|
@ -41,20 +42,20 @@ class Example(Data):
|
||||||
|
|
||||||
def import_xml(self, example_xml):
|
def import_xml(self, example_xml):
|
||||||
self.translations = from_container_list(example_xml.querySelectorAll("translationContainerList translationContainer"))
|
self.translations = from_container_list(example_xml.querySelectorAll("translationContainerList translationContainer"))
|
||||||
|
self.original_xml = example_xml.cloneNode(True)
|
||||||
if example_xml.hasAttribute("modified"):
|
if example_xml.hasAttribute("modified"):
|
||||||
self.edited = example_xml.getAttribute("modified") == "true"
|
self.edited = example_xml.getAttribute("modified") == "true"
|
||||||
|
|
||||||
inner_xml = example_xml.querySelector("corpusExample")
|
inner_xml = self.original_xml.querySelector("corpusExample")
|
||||||
if inner_xml is not None:
|
if inner_xml is not None:
|
||||||
self.inner = CorpusExample()
|
self.inner = CorpusExample()
|
||||||
else:
|
else:
|
||||||
inner_xml = example_xml.querySelector("multiwordExample")
|
inner_xml = self.original_xml.querySelector("multiwordExample")
|
||||||
self.inner = MultiwordExample()
|
self.inner = MultiwordExample()
|
||||||
|
|
||||||
self.inner.import_xml(inner_xml)
|
self.inner.import_xml(inner_xml)
|
||||||
|
|
||||||
for idx, comp_xml in enumerate(inner_xml.childNodes):
|
for idx, comp_xml in enumerate(self.inner.original_xml.childNodes):
|
||||||
comp = ComponentLexeme()
|
comp = ComponentLexeme()
|
||||||
comp.import_xml(comp_xml)
|
comp.import_xml(comp_xml)
|
||||||
if comp.isValid():
|
if comp.isValid():
|
||||||
|
@ -62,11 +63,10 @@ class Example(Data):
|
||||||
|
|
||||||
self.check_multiword_components()
|
self.check_multiword_components()
|
||||||
|
|
||||||
def export(self, doc):
|
def export(self, doc, xml_parent):
|
||||||
self.check_multiword_components()
|
self.check_multiword_components()
|
||||||
|
result = self.original_xml if self.original_xml != None else doc.createElement("exampleContainer")
|
||||||
result = doc.createElement("exampleContainer")
|
xml_parent.appendChild(result)
|
||||||
|
|
||||||
inner = self.inner.export(doc, self.edited)
|
inner = self.inner.export(doc, self.edited)
|
||||||
# TODO: bad quick fix
|
# TODO: bad quick fix
|
||||||
for comp in self.components:
|
for comp in self.components:
|
||||||
|
|
|
@ -6,8 +6,10 @@ class MultiwordExample:
|
||||||
self.other_attributes = {}
|
self.other_attributes = {}
|
||||||
self.cluster = -1
|
self.cluster = -1
|
||||||
self.type = None
|
self.type = None
|
||||||
|
self.original_xml = None
|
||||||
|
|
||||||
def import_xml(self, example_xml):
|
def import_xml(self, example_xml):
|
||||||
|
self.original_xml = example_xml.cloneNode(True)
|
||||||
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)
|
||||||
|
@ -17,6 +19,9 @@ class MultiwordExample:
|
||||||
if example_xml.hasAttribute("type"):
|
if example_xml.hasAttribute("type"):
|
||||||
self.type = example_xml.getAttribute("type")
|
self.type = example_xml.getAttribute("type")
|
||||||
|
|
||||||
|
|
||||||
|
example_xml.remove()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _determine_cluster_number(example_xml):
|
def _determine_cluster_number(example_xml):
|
||||||
if not example_xml.hasAttribute("cluster"):
|
if not example_xml.hasAttribute("cluster"):
|
||||||
|
@ -27,8 +32,8 @@ class MultiwordExample:
|
||||||
return cluster
|
return cluster
|
||||||
|
|
||||||
def export(self, doc, _modified):
|
def export(self, doc, _modified):
|
||||||
result = doc.createElement("multiwordExample")
|
result = self.original_xml if self.original_xml is not None else doc.createElement("multiwordExample")
|
||||||
|
# result = doc.createElement("multiwordExample")
|
||||||
for key, value in self.other_attributes.items():
|
for key, value in self.other_attributes.items():
|
||||||
result.setAttribute(key, value)
|
result.setAttribute(key, value)
|
||||||
|
|
||||||
|
|
|
@ -7,14 +7,15 @@ class Explanation(Data):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.value = ""
|
self.value = ""
|
||||||
self.language = ""
|
self.language = ""
|
||||||
|
self.original_xml = None
|
||||||
|
|
||||||
def import_dom(self, explanation_dom):
|
def import_dom(self, explanation_xml):
|
||||||
|
self.original_xml = explanation_xml.cloneNode(True)
|
||||||
self.value = explanation_dom.textContent if explanation_dom else ""
|
self.value = explanation_xml.textContent if explanation_xml else ""
|
||||||
self.language = explanation_dom.getAttribute("language") if explanation_dom.hasAttribute("language") else ""
|
self.language = explanation_xml.getAttribute("language") if explanation_xml.hasAttribute("language") else ""
|
||||||
|
|
||||||
def export(self, doc):
|
def export(self, doc):
|
||||||
result = doc.createElement("explanation")
|
result = self.original_xml if self.original_xml != None else doc.createElement("explanation")
|
||||||
result.textContent = self.value
|
result.textContent = self.value
|
||||||
if self.language != "": result.setAttribute('language', self.language)
|
if self.language != "": result.setAttribute('language', self.language)
|
||||||
|
|
||||||
|
|
|
@ -11,25 +11,34 @@ from view.utils import clean_label
|
||||||
class Sense(Data):
|
class Sense(Data):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.original_idx = -1
|
self.original_idx = -1
|
||||||
self.definition = {}
|
self.original_xml = None
|
||||||
|
self.definitions = []
|
||||||
self.labels = []
|
self.labels = []
|
||||||
self.translations = []
|
self.translations = []
|
||||||
self.examples = []
|
self.examples = []
|
||||||
|
|
||||||
def import_xml(self, sense_xml, idx):
|
def import_xml(self, sense_xml, idx):
|
||||||
self.original_idx = idx
|
self.original_idx = idx
|
||||||
|
self.original_xml = sense_xml.cloneNode(True)
|
||||||
|
|
||||||
for definition in sense_xml.querySelectorAll("definitionList definition"):
|
for definition in self.original_xml.querySelectorAll("definitionList definition"):
|
||||||
key = definition.getAttribute("type")
|
definition_object = {}
|
||||||
self.definition[key] = definition.textContent
|
definition_object.type = definition.getAttribute("type")
|
||||||
|
definition_object.value = definition.textContent
|
||||||
|
definition_object.original_xml = definition
|
||||||
|
definition.remove()
|
||||||
|
self.definitions.append(definition_object)
|
||||||
|
|
||||||
self.labels = import_label_list("sense > labelList label", sense_xml)
|
self.labels = import_label_list("sense > labelList label", self.original_xml)
|
||||||
self.translations = from_container_list(
|
self.translations = from_container_list(
|
||||||
sense_xml.querySelectorAll('sense > translationContainerList translationContainer'))
|
self.original_xml.querySelectorAll('sense > translationContainerList translationContainer'))
|
||||||
for example_xml in sense_xml.querySelectorAll("exampleContainerList exampleContainer"):
|
for example_xml in self.original_xml.querySelectorAll("exampleContainerList exampleContainer"):
|
||||||
example = Example()
|
example = Example()
|
||||||
example.import_xml(example_xml)
|
example.import_xml(example_xml)
|
||||||
self.examples.append(example)
|
self.examples.append(example)
|
||||||
|
example_xml.remove()
|
||||||
|
|
||||||
|
console.log(self.original_xml)
|
||||||
|
|
||||||
|
|
||||||
def merge_labels(self):
|
def merge_labels(self):
|
||||||
|
@ -44,7 +53,7 @@ class Sense(Data):
|
||||||
h("div.sense", {}, [
|
h("div.sense", {}, [
|
||||||
h("span.sense-label-list", { "on": { "click": M.msg(M.ShowSenseLabelEdit, self) }}, [
|
h("span.sense-label-list", { "on": { "click": M.msg(M.ShowSenseLabelEdit, self) }}, [
|
||||||
h("span.sense-label", {}, clean_label(slabel)) for _, slabel in self.labels ]),
|
h("span.sense-label", {}, clean_label(slabel)) for _, slabel in self.labels ]),
|
||||||
h("span.sense-definition", { "on": { "click": M.msg(M.ShowSenseDefinitionEdit, self) }}, self.definition["indicator"]),
|
h("span.sense-definition", { "on": { "click": M.msg(M.ShowSenseDefinitionEdit, self) }}, ", ".join(d.value for d in self.definitions)),
|
||||||
h("div", {}, View.view_translations(self.translations, self, model)),
|
h("div", {}, View.view_translations(self.translations, self, model)),
|
||||||
h("div", {}, examples)])])
|
h("div", {}, examples)])])
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -35,12 +35,12 @@ STYLE_SECTIONS = [("registrske", "register"),
|
||||||
|
|
||||||
def import_label_list(selector, xml_element):
|
def import_label_list(selector, xml_element):
|
||||||
result = []
|
result = []
|
||||||
for tag_xml in xml_element.querySelectorAll(selector):
|
for index, tag_xml in enumerate(xml_element.querySelectorAll(selector)):
|
||||||
t_type = tag_xml.getAttribute("type")
|
t_type = tag_xml.getAttribute("type")
|
||||||
t_value = tag_xml.textContent
|
t_value = tag_xml.textContent
|
||||||
|
|
||||||
t_type, t_value = import_tag(t_type, t_value)
|
t_type, t_value = import_tag(t_type, t_value)
|
||||||
result.append((t_type, t_value))
|
result.append((t_type, t_value, index))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@ def from_container_list(translation_list_container_xml):
|
||||||
t = Translation()
|
t = Translation()
|
||||||
t.import_xml(translation_xml)
|
t.import_xml(translation_xml)
|
||||||
translations.append((num_cluster, t))
|
translations.append((num_cluster, t))
|
||||||
|
translation_xml.remove()
|
||||||
|
|
||||||
|
|
||||||
result = [[] for _ in range(max_num_cluster)]
|
result = [[] for _ in range(max_num_cluster)]
|
||||||
for clusterNum, translation in translations:
|
for clusterNum, translation in translations:
|
||||||
|
@ -30,6 +32,7 @@ def from_container_list(translation_list_container_xml):
|
||||||
|
|
||||||
class Translation(Data):
|
class Translation(Data):
|
||||||
def __init__(self, translation_xml):
|
def __init__(self, translation_xml):
|
||||||
|
self.original_xml = None
|
||||||
self.translation = ""
|
self.translation = ""
|
||||||
self.source = ""
|
self.source = ""
|
||||||
self.targetLang = ""
|
self.targetLang = ""
|
||||||
|
@ -39,6 +42,7 @@ class Translation(Data):
|
||||||
|
|
||||||
def import_xml(self, translation_xml):
|
def import_xml(self, translation_xml):
|
||||||
translation = translation_xml.querySelector("translation")
|
translation = translation_xml.querySelector("translation")
|
||||||
|
self.original_xml = translation_xml.cloneNode(True)
|
||||||
|
|
||||||
if translation:
|
if translation:
|
||||||
self.translation = translation.textContent
|
self.translation = translation.textContent
|
||||||
|
@ -46,13 +50,13 @@ class Translation(Data):
|
||||||
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 ""
|
self.audio = translation.getAttribute("audio") if translation.hasAttribute("audio") else ""
|
||||||
|
|
||||||
explanationList = translation_xml.querySelectorAll("explanationList explanation")
|
explanationList = self.original_xml.querySelectorAll("explanationList explanation")
|
||||||
for explanation_dom in explanationList:
|
for explanation_dom in explanationList:
|
||||||
explanation = Explanation()
|
explanation = Explanation()
|
||||||
explanation.import_dom(explanation_dom)
|
explanation.import_dom(explanation_dom)
|
||||||
self.explanationList.append(explanation)
|
self.explanationList.append(explanation)
|
||||||
|
explanation_dom.remove()
|
||||||
self.tags = import_label_list("labelList label", translation_xml)
|
self.tags = import_label_list("labelList label", self.original_xml)
|
||||||
|
|
||||||
def view(self, model):
|
def view(self, model):
|
||||||
elements = []
|
elements = []
|
||||||
|
|
|
@ -42,15 +42,19 @@ def question(question, current_value):
|
||||||
def generic_list_editor(title, element_list_getter):
|
def generic_list_editor(title, element_list_getter):
|
||||||
content = [h("p", {}, title)]
|
content = [h("p", {}, title)]
|
||||||
for slabel in element_list_getter():
|
for slabel in element_list_getter():
|
||||||
|
idAttr = {"data-id": slabel.id} if slabel.id >= 0 else {}
|
||||||
content.append(h("label", {}, [
|
content.append(h("label", {}, [
|
||||||
h("input.list-adder-input", {"props": {"type": "text", "value": slabel}}, "")]))
|
h("input.list-adder-input", {"props": {"type": "text", "value": slabel.value or slabel}, "attrs": idAttr}, "")]))
|
||||||
|
|
||||||
|
console.log(content)
|
||||||
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, element_list_getter)}}, "+"))
|
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, element_list_getter)}}, "+"))
|
||||||
return content
|
return content
|
||||||
|
|
||||||
def homonymy_editor(title, current_labels):
|
def homonymy_editor(title, current_labels):
|
||||||
def split_line2(left, right):
|
def split_line2(left, right, labelId):
|
||||||
cls = "flex.two{}".format(".double-list-row")
|
cls = "flex.two{}".format(".double-list-row")
|
||||||
return h("div.{}".format(cls), {}, [
|
isId = {"attrs": {"data-id": labelId}} if labelId >= 0 else {}
|
||||||
|
return h("div.{}".format(cls), isId, [
|
||||||
h("div.half", {}, left), h("div.half", {}, right)])
|
h("div.half", {}, left), h("div.half", {}, right)])
|
||||||
|
|
||||||
content = [h("p", {}, title)]
|
content = [h("p", {}, title)]
|
||||||
|
@ -58,19 +62,20 @@ def homonymy_editor(title, current_labels):
|
||||||
name = []
|
name = []
|
||||||
value = []
|
value = []
|
||||||
name.append(h("label", {"attrs": {"for": i}}, "Name:"))
|
name.append(h("label", {"attrs": {"for": i}}, "Name:"))
|
||||||
name.append(h("input.name-input", {"props": {"type": "text", "value": feature["name"], "id": i}}, ""))
|
name.append(h("input.name-input", {"props": {"type": "text", "value": feature["name"], "id": i, "data-id": feature.id}}, ""))
|
||||||
value.append(h("label", {"attrs": {"for": i + "-value"}}, "Value:"))
|
value.append(h("label", {"attrs": {"for": i + "-value"}}, "Value:"))
|
||||||
value.append(h("input.value-input", {"props": {"type": "text", "value": feature["value"], "id": i + "-value"}}, ""))
|
value.append(h("input.value-input", {"props": {"type": "text", "value": feature["value"], "id": i + "-value"}}, ""))
|
||||||
|
|
||||||
content.append(split_line2(name, value))
|
content.append(split_line2(name, value, feature.id))
|
||||||
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, current_labels)}}, "+"))
|
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, current_labels)}}, "+"))
|
||||||
|
|
||||||
return content
|
return content
|
||||||
|
|
||||||
def explanation_editor(title, current_labels):
|
def explanation_editor(title, current_labels):
|
||||||
def split_line2(left, right):
|
def split_line2(left, right, labelId):
|
||||||
cls = "flex.two{}".format(".double-list-row")
|
cls = "flex.two{}".format(".double-list-row")
|
||||||
return h("div.{}".format(cls), {}, [
|
isId = {"attrs": {"data-id": labelId}} if labelId >= 0 else {}
|
||||||
|
return h("div.{}".format(cls), isId, [
|
||||||
h("div.four-fifth", {}, left), h("div.fifth", {}, right)])
|
h("div.four-fifth", {}, left), h("div.fifth", {}, right)])
|
||||||
|
|
||||||
content = [h("p", {}, title)]
|
content = [h("p", {}, title)]
|
||||||
|
@ -82,7 +87,7 @@ def explanation_editor(title, current_labels):
|
||||||
value.append(h("label", {"attrs": {"for": i + "-value"}}, "Value:"))
|
value.append(h("label", {"attrs": {"for": i + "-value"}}, "Value:"))
|
||||||
value.append(h("input.value-input", {"props": {"type": "text", "value": explanation["value"], "id": i + "-value"}}, ""))
|
value.append(h("input.value-input", {"props": {"type": "text", "value": explanation["value"], "id": i + "-value"}}, ""))
|
||||||
|
|
||||||
content.append(split_line2(value, language))
|
content.append(split_line2(value, language, explanation.id))
|
||||||
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, current_labels)}}, "+"))
|
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, current_labels)}}, "+"))
|
||||||
|
|
||||||
return content
|
return content
|
||||||
|
@ -90,12 +95,13 @@ def explanation_editor(title, current_labels):
|
||||||
|
|
||||||
|
|
||||||
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, labelId, is_llr=True):
|
||||||
|
isId = {"attrs": {"data-id": labelId}} if labelId >= 0 else {}
|
||||||
cls = "flex.three{}".format(".label-list-row" if is_llr else "")
|
cls = "flex.three{}".format(".label-list-row" if is_llr else "")
|
||||||
return h("div.{}".format(cls), {}, [
|
return h("div.{}".format(cls), isId, [
|
||||||
h("span.third", {}, left), h("span.third", {}, center), h("span.third", {}, right)])
|
h("span.third", {}, left), h("span.third", {}, center), h("span.third", {}, right)])
|
||||||
|
|
||||||
def dropdown_right(label_type, label):
|
def dropdown_right(label_type, label, index):
|
||||||
left = h("span.label-type", {}, label_type)
|
left = h("span.label-type", {}, label_type)
|
||||||
|
|
||||||
options = [h("option", {}, [])]
|
options = [h("option", {}, [])]
|
||||||
|
@ -108,17 +114,16 @@ def label_list_editor(current_labels, add_label_message_class):
|
||||||
{"props": {"type": "text", "value": right_value, "placeholder": "drugo"}},
|
{"props": {"type": "text", "value": right_value, "placeholder": "drugo"}},
|
||||||
[])
|
[])
|
||||||
|
|
||||||
return split_line3(left, center, right)
|
return split_line3(left, center, right, index)
|
||||||
|
|
||||||
content = []
|
content = []
|
||||||
kontrastivno = False
|
kontrastivno = False
|
||||||
for key, value in current_labels:
|
for key, value, idx in current_labels:
|
||||||
# we will show kontrastivno a bit differently
|
# we will show kontrastivno a bit differently
|
||||||
if value == "kontrastivno":
|
if value == "kontrastivno":
|
||||||
kontrastivno = True
|
kontrastivno = True
|
||||||
continue
|
continue
|
||||||
|
content.append(dropdown_right(key, value, (idx if idx >= 0 else -1)))
|
||||||
content.append(dropdown_right(key, value))
|
|
||||||
|
|
||||||
# add a way to get new element to add to tag list
|
# add a way to get new element to add to tag list
|
||||||
def get_new_label_type():
|
def get_new_label_type():
|
||||||
|
|
|
@ -40,7 +40,9 @@ def edit_sense_label(sense):
|
||||||
|
|
||||||
def edit_example(example, sense):
|
def edit_example(example, sense):
|
||||||
example_original = example
|
example_original = example
|
||||||
example = example_original.copy()
|
# example = example_original.deepcopy()
|
||||||
|
# example = copy.deepcopy(example)
|
||||||
|
# example.original_xml = example_original.original_xml.cloneNode(True)
|
||||||
|
|
||||||
def role_msg(idx, role):
|
def role_msg(idx, role):
|
||||||
return message.msg(message.ExampleRoleChange, example_original, idx, role)
|
return message.msg(message.ExampleRoleChange, example_original, idx, role)
|
||||||
|
@ -100,6 +102,7 @@ def edit_variants(entry):
|
||||||
|
|
||||||
def edit_homonymy(entry):
|
def edit_homonymy(entry):
|
||||||
hget = lambda: entry.copy().homonymy
|
hget = lambda: entry.copy().homonymy
|
||||||
|
console.log(hget)
|
||||||
content = homonymy_editor("Homonymy", hget)
|
content = homonymy_editor("Homonymy", hget)
|
||||||
return modal_template(content, "Add or remove homonymy features", (message.EditHomonymy,), (message.DeleteHomonymy,))
|
return modal_template(content, "Add or remove homonymy features", (message.EditHomonymy,), (message.DeleteHomonymy,))
|
||||||
|
|
||||||
|
@ -116,7 +119,7 @@ def edit_entry_labels(entry):
|
||||||
|
|
||||||
|
|
||||||
def edit_sense_definition(sense):
|
def edit_sense_definition(sense):
|
||||||
return modal_template(question("Edit sense definition", sense.definition["indicator"]), "Sense definition", (message.EditSenseDefinition, sense))
|
return modal_template(question("Edit sense definition", sense.definitions[0].value), "Sense definition", (message.EditSenseDefinition, sense))
|
||||||
|
|
||||||
|
|
||||||
def edit_comment(comment):
|
def edit_comment(comment):
|
||||||
|
@ -135,7 +138,7 @@ def do_chosen_examples(example_list, entry):
|
||||||
|
|
||||||
options = [h("p", {}, "Choose sense for examples")]
|
options = [h("p", {}, "Choose sense for examples")]
|
||||||
for idx, sense in enumerate(entry.senses):
|
for idx, sense in enumerate(entry.senses):
|
||||||
text = "{}: {}".format(idx + 1, sense.definition["indicator"])
|
text = "{}: {}".format(idx + 1, sense.definitions[0].value)
|
||||||
id_ = "choose-example-{}".format(idx)
|
id_ = "choose-example-{}".format(idx)
|
||||||
|
|
||||||
props = {"type": "radio", "name": "choose-example"}
|
props = {"type": "radio", "name": "choose-example"}
|
||||||
|
@ -185,6 +188,6 @@ def ske_list(search_term, data, page_num, senses, ske_kinds):
|
||||||
h("div.flex.three", {}, [
|
h("div.flex.three", {}, [
|
||||||
h("span.third", {}, "Vstavi v:"),
|
h("span.third", {}, "Vstavi v:"),
|
||||||
h("select#ske-sense-select.two-third", {}, [ h("option", {}, "{} {}".format(
|
h("select#ske-sense-select.two-third", {}, [ h("option", {}, "{} {}".format(
|
||||||
idx + 1, sense.definition["indicator"])) for idx, sense in enumerate(senses)])])]
|
idx + 1, sense.definitions[0].value)) for idx, sense in enumerate(senses)])])]
|
||||||
|
|
||||||
return modal_template(contents, "SKE", (message.SkeInsert, data))
|
return modal_template(contents, "SKE", (message.SkeInsert, data))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user