wip, save spot for keeping explanation data

This commit is contained in:
matic_t 2020-08-25 05:56:48 -07:00
parent e1ce093ff6
commit 48a91ed67a
8 changed files with 52 additions and 31 deletions

View File

@ -91,25 +91,30 @@ def export_entry(entry):
# Same problem as homonymy
variants = _original_xml_query_selector("head variantList", entry, doc)
original_variants = entry.original_xml.querySelectorAll("head variantList variant")
og_variants = entry.original_xml.querySelectorAll("head variantList variant")
for v in entry.variants:
variant = doc.createElement("variant")
if v.id >= 0:
variant = original_variants[v.id]
variant = og_variants[v.id]
else:
variants.appendChild(variant)
variant.textContent = v.value
variants.appendChild(variant)
# relist = _original_xml_query_selector("head relatedEntryList", entry, doc)
relist = doc.createElement("relatedEntryList")
head.appendChild(relist.cloneNode(True))
# 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:
relateEntry = doc.createElement("relatedEntry")
relateEntry.textContent = re
relist.appendChild(relateEntry)
if re.id >= 0:
relateEntry = og_relist[re.id]
else:
relist.appendChild(relateEntry)
relateEntry.textContent = re.value
head.appendChild(_export_label_list(doc, entry.labels))
@ -129,12 +134,12 @@ def export_entry(entry):
sense_list = doc.createElement("senseList")
for sense in entry.senses:
sense_list.appendChild(export_sense(doc, sense))
sense_list.appendChild(export_sense(doc, sense, entry))
return entry.original_xml
def export_sense(doc, sense):
def export_sense(doc, sense, entry):
sense_xml = doc.createElement("sense")
sense_xml.appendChild(_export_label_list(doc, sense.labels))
@ -148,7 +153,7 @@ def export_sense(doc, sense):
definition_list.appendChild(definition)
translation_container_list = doc.createElement("translationContainerList")
export_translation_list(doc, sense, translation_container_list)
export_translation_list(doc, sense, translation_container_list, entry)
sense_xml.appendChild(translation_container_list)
example_container_list = doc.createElement("exampleContainerList")
@ -157,21 +162,21 @@ def export_sense(doc, sense):
for example in sense.examples:
example_container = example.export(doc)
translation_container_list = doc.createElement("translationContainerList")
export_translation_list(doc, example, translation_container_list)
export_translation_list(doc, example, translation_container_list, entry)
example_container.appendChild(translation_container_list)
example_container_list.appendChild(example_container)
return sense_xml
def export_translation_list(doc, py_parent, xml_parent):
def export_translation_list(doc, py_parent, xml_parent, entry):
for cidx, cluster in enumerate(py_parent.translations):
for translation in cluster:
translation_container = export_translation(doc, translation)
translation_container = export_translation(doc, translation, entry)
translation_container.setAttribute("cluster", str(cidx + 1))
xml_parent.appendChild(translation_container)
def export_translation(doc, translation):
def export_translation(doc, translation, entry):
translation_xml = doc.createElement("translationContainer")
translation_xml.appendChild(_export_label_list(doc, translation.tags))
@ -187,15 +192,19 @@ def export_translation(doc, translation):
translation_xml.appendChild(actual_t)
if len(translation.explanationList) > 0 :
explanationList = _export_explanation_list(doc, translation.explanationList)
explanationList = _export_explanation_list(doc, translation.explanationList, entry)
translation_xml.appendChild(explanationList)
return translation_xml
def _export_explanation_list(doc, lst):
def _export_explanation_list(doc, lst, entry):
debugger
# relist = _original_xml_query_selector("head relatedEntryList", entry, doc)
# og_relist = entry.original_xml.querySelectorAll("head relatedEntryList relatedEntry")
result = doc.createElement('explanationList')
for explanation in lst:
result.appendChild(explanation.export(doc))

View File

@ -86,7 +86,7 @@ class DoChosenExamples(Message):
class EditVariants(Message):
def update_model(self, model):
variants = common_accessors.generic_list_getter()
_remove_deleted_quries(variants, "head variantList variant", model)
update_entries(variants, "head variantList variant", model)
console.log(variants)
model.entry.variants = variants
@ -94,7 +94,7 @@ class EditHomonymy(Message):
def update_model(self, model):
homonymy = common_accessors.double_list_getter("value", "name")
_remove_deleted_quries(homonymy, "head headword homonymy homonymyFeature", model)
update_entries(homonymy, "head headword homonymy homonymyFeature", model)
model.entry.homonymy = homonymy
@ -102,6 +102,7 @@ class EditHomonymy(Message):
class EditRelatedEntries(Message):
def update_model(self, model):
related_entries = common_accessors.generic_list_getter()
update_entries(related_entries, "head relatedEntryList relatedEntry", model)
model.entry.related_entries = related_entries
@ -124,7 +125,7 @@ class ExampleClusterAdd(DataChgClickMessage):
example.set_cluster(ExampleClusters.first_empty_cluster())
def _remove_deleted_quries(updated_list, query, model):
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):

View File

@ -1,5 +1,6 @@
from message.message import Message
from message.simple_messages import DataChgClickMessage
from message.simple_edits import update_entries
import message.common_accessors as common_accessors
from browser import document, window
from model.translation import Translation
@ -14,14 +15,20 @@ class EditTranslation(DataChgClickMessage):
self.old_cluster_idx = self.get_arg(1, int)
self.translation.translation = document.getElementById("etv").value
# 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)
update_entries(explanations, "explanationList explanation", model)
self.translation.explanationList = []
for entry in explanations:
explanation = Explanation()
explanation.value = entry.value
explanation.language = entry.language
explanation.id = entry.id
self.translation.explanationList.append(explanation)
console.log(self.translation.explanationList)
console.log(model)
# common_accessors.label_list_getter()
self.translation.tags = common_accessors.label_list_getter()

View File

@ -41,7 +41,7 @@ class Entry(Data):
self.comment = comment.textContent if comment else ""
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"), "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")
if lex_unit:
@ -96,7 +96,7 @@ class Entry(Data):
if len(self.variants) == 0:
view_buttons.append(buttons[0])
else:
view_table.append((buttons[0], ", ".join(h.value for h in self.variants)))
view_table.append((buttons[0], ", ".join(v.value for v in self.variants)))
if len(self.homonymy) == 0:
view_buttons.append(buttons[4])
@ -106,7 +106,7 @@ class Entry(Data):
if len(self.related_entries) == 0:
view_buttons.append(buttons[1])
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:
view_buttons.append(buttons[2])

View File

@ -7,15 +7,18 @@ class Explanation(Data):
def __init__(self):
self.value = ""
self.language = ""
self.id = -1
def import_dom(self, explanation_dom):
def import_dom(self, explanation_dom, index):
self.value = explanation_dom.textContent if explanation_dom else ""
self.language = explanation_dom.getAttribute("language") if explanation_dom.hasAttribute("language") else ""
self.id = index
def export(self, doc):
result = doc.createElement("explanation")
result.textContent = self.value
if self.language != "": result.setAttribute('language', self.language)
if self.id >= 0: result.setAttribute('id', self.id)
return result

View File

@ -26,9 +26,9 @@ class Sense(Data):
self.labels = import_label_list("sense > labelList label", sense_xml)
self.translations = from_container_list(
sense_xml.querySelectorAll('sense > translationContainerList translationContainer'))
for example_xml in sense_xml.querySelectorAll("exampleContainerList exampleContainer"):
for index, example_xml in enumerate(sense_xml.querySelectorAll("exampleContainerList exampleContainer")):
example = Example()
example.import_xml(example_xml)
example.import_xml(example_xml, index)
self.examples.append(example)

View File

@ -47,11 +47,11 @@ class Translation(Data):
self.audio = translation.getAttribute("audio") if translation.hasAttribute("audio") else ""
explanationList = translation_xml.querySelectorAll("explanationList explanation")
for explanation_dom in explanationList:
for index, explanation_dom in enumerate(explanationList):
explanation = Explanation()
explanation.import_dom(explanation_dom)
explanation.import_dom(explanation_dom, index)
self.explanationList.append(explanation)
console.log(self.explanationList)
self.tags = import_label_list("labelList label", translation_xml)
def view(self, model):

View File

@ -72,8 +72,9 @@ def homonymy_editor(title, current_labels):
return content
def explanation_editor(title, current_labels):
def split_line2(left, right):
def split_line2(left, right, labelId):
cls = "flex.two{}".format(".double-list-row")
isId = {"attrs": {"data-id": labelId}} if labelId >= 0 else {}
return h("div.{}".format(cls), {}, [
h("div.four-fifth", {}, left), h("div.fifth", {}, right)])
@ -86,7 +87,7 @@ def explanation_editor(title, current_labels):
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(split_line2(value, language, explanation.id))
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, current_labels)}}, "+"))
return content