Compare commits
10 Commits
mt-dont-de
...
master
Author | SHA1 | Date | |
---|---|---|---|
300f90822c | |||
|
37980d56e5 | ||
|
0b2bf53a6f | ||
c7a405fc46 | |||
4812c18a1d | |||
197cc6199c | |||
19d3e38dcb | |||
|
76c80baa09 | ||
8802a09c9c | |||
|
04c8bc1471 |
235
src/export.py
235
src/export.py
|
@ -7,197 +7,151 @@ def export_to_xml(model):
|
|||
serializer = __new__(XMLSerializer())
|
||||
return serializer.serializeToString(xml_document)
|
||||
|
||||
|
||||
def export_entry(entry):
|
||||
parser = __new__(DOMParser())
|
||||
doc = parser.parseFromString("<entry />", "text/xml")
|
||||
entry_xml = doc.firstChild
|
||||
|
||||
# create head
|
||||
head = entry.original_xml.querySelector("head")
|
||||
if head is None:
|
||||
head = doc.createElement("head")
|
||||
entry.original_xml.appendChild(head)
|
||||
# entry_xml.appendChild(head.cloneNode(True))
|
||||
head = doc.createElement("head")
|
||||
entry_xml.appendChild(head)
|
||||
|
||||
status = _original_xml_query_selector("head status", entry, doc)
|
||||
status = doc.createElement("status")
|
||||
status.textContent = entry.status
|
||||
# head.appendChild(status.cloneNode(True))
|
||||
head.appendChild(status)
|
||||
|
||||
headword = doc.createElement("headword")
|
||||
headword_lemma = doc.createElement("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 = entry.original_xml.querySelector("head headword lemma")
|
||||
|
||||
headword_lemma.textContent = entry.headword
|
||||
if entry.headword_type is not None:
|
||||
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)
|
||||
head.appendChild(headword)
|
||||
|
||||
# headword.appendChild(headword_lemma.cloneNode(True))
|
||||
# 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")
|
||||
homonymy = doc.createElement("homonymy")
|
||||
headword.appendChild(homonymy)
|
||||
|
||||
for hFeature in entry.homonymy:
|
||||
feature = doc.createElement("homonymyFeature")
|
||||
if hFeature.id >= 0:
|
||||
feature = original_homonymy[hFeature.id]
|
||||
else:
|
||||
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
|
||||
# Can't use hFeature.name, because Python has name reserver and so it becomes py_name in JS
|
||||
feature.setAttribute("name", hFeature["name"])
|
||||
|
||||
homonymy.appendChild(feature)
|
||||
|
||||
|
||||
# if({}) works uncorrectly in transcrypt
|
||||
if len(entry.lexical_unit) > 0:
|
||||
lexunit = _original_xml_query_selector("head lexicalUnit", entry, doc)
|
||||
# lexunit = doc.createElement("lexicalUnit")
|
||||
lexunit = doc.createElement("lexicalUnit")
|
||||
lexunit.setAttribute("id", entry.lexical_unit["id"])
|
||||
lexunit.setAttribute("type", "single")
|
||||
lexeme = _original_xml_query_selector("head lexicalUnit lexeme", entry, doc)
|
||||
# lexeme = doc.createElement("lexeme")
|
||||
lexeme = doc.createElement("lexeme")
|
||||
lexeme.setAttribute("lexical_unit_lexeme_id", entry.lexical_unit["id"])
|
||||
lexeme.textContent = entry.lexical_unit["text"]
|
||||
|
||||
# lexunit.appendChild(lexeme.cloneNode(True))
|
||||
# head.appendChild(lexunit.cloneNode(True))
|
||||
lexunit.appendChild(lexeme)
|
||||
head.appendChild(lexunit)
|
||||
|
||||
# Example of keeping original xml and adding changes to it only
|
||||
grammar = _original_xml_query_selector("head grammar", entry, doc)
|
||||
grammar_category = _original_xml_query_selector("head grammar category", entry, doc)
|
||||
|
||||
grammar = doc.createElement("grammar")
|
||||
grammar_category = doc.createElement("category")
|
||||
grammar_category.textContent = entry.grammar
|
||||
grammar.appendChild(grammar_category)
|
||||
head.appendChild(grammar)
|
||||
|
||||
# head.appendChild(grammar.cloneNode(True))
|
||||
console.log(entry.original_xml)
|
||||
|
||||
if len(entry.measure) > 0:
|
||||
measure_list = _original_xml_query_selector("head measureList", entry, doc)
|
||||
measure = _original_xml_query_selector("head measureList measure", entry, doc)
|
||||
|
||||
# measure_list = doc.createElement("measureList")
|
||||
# measure = doc.createElement("measure")
|
||||
measure_list = doc.createElement("measureList")
|
||||
measure = doc.createElement("measure")
|
||||
measure.setAttribute("source", entry.measure["source"])
|
||||
measure.setAttribute("type", entry.measure["type"])
|
||||
measure.textContent = entry.measure["text"]
|
||||
|
||||
# head.appendChild(measure_list)
|
||||
measure_list.appendChild(measure)
|
||||
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:
|
||||
variant = doc.createElement("variant")
|
||||
if v.id >= 0:
|
||||
variant = og_variants[v.id]
|
||||
else:
|
||||
variants.appendChild(variant)
|
||||
variant.textContent = v
|
||||
variants.appendChild(variant)
|
||||
|
||||
variant.textContent = v.value
|
||||
relist = doc.createElement("relatedEntryList")
|
||||
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:
|
||||
relateEntry = doc.createElement("relatedEntry")
|
||||
relateEntry.textContent = re
|
||||
relist.appendChild(relateEntry)
|
||||
|
||||
if re.id >= 0:
|
||||
relateEntry = og_relist[re.id]
|
||||
else:
|
||||
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 = _original_xml_query_selector("head comment", entry, doc)
|
||||
comment = doc.createElement("comment")
|
||||
comment.textContent = entry.comment
|
||||
# head.appendChild(comment.cloneNode(True))
|
||||
head.appendChild(comment)
|
||||
|
||||
# now lets do body
|
||||
body = doc.createElement("body")
|
||||
entry_xml.appendChild(body)
|
||||
|
||||
body = entry.original_xml.querySelector("body")
|
||||
if body is None:
|
||||
body = doc.createElement("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:
|
||||
sense_xml = doc.createElement("sense")
|
||||
sense_list.appendChild(export_sense(doc, sense))
|
||||
|
||||
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
|
||||
return doc
|
||||
|
||||
|
||||
def export_sense(doc, sense, sense_xml):
|
||||
_export_label_list(doc, sense.labels, sense_xml)
|
||||
def export_sense(doc, sense):
|
||||
sense_xml = doc.createElement("sense")
|
||||
sense_xml.appendChild(_export_label_list(doc, sense.labels))
|
||||
|
||||
definition_list = sense_xml.querySelector("definitionList")
|
||||
if definition_list is None:
|
||||
definition_list = doc.createElement("definitionList")
|
||||
sense_xml.appendChild(definition_list)
|
||||
definition_list = doc.createElement("definitionList")
|
||||
sense_xml.appendChild(definition_list)
|
||||
|
||||
for definition in sense.definitions:
|
||||
definition_xml = definition.original_xml if definition.original_xml != None else doc.createElement("definition")
|
||||
definition_list.appendChild(definition_xml)
|
||||
definition_xml.textContent = definition.value
|
||||
definition_xml.setAttribute("type", definition.type)
|
||||
for typ, text in sense.definition.items():
|
||||
definition = doc.createElement("definition")
|
||||
definition.textContent = text
|
||||
definition.setAttribute("type", typ)
|
||||
definition_list.appendChild(definition)
|
||||
|
||||
translation_container_list = sense_xml.querySelector("sense > translationContainerList")
|
||||
if translation_container_list is None:
|
||||
translation_container_list = doc.createElement("translationContainerList")
|
||||
sense_xml.appendChild(translation_container_list)
|
||||
translation_container_list = doc.createElement("translationContainerList")
|
||||
export_translation_list(doc, sense, translation_container_list)
|
||||
sense_xml.appendChild(translation_container_list)
|
||||
|
||||
example_container_list = sense_xml.querySelector("sense > exampleContainerList")
|
||||
if example_container_list is None:
|
||||
example_container_list = doc.createElement("exampleContainerList")
|
||||
sense_xml.appendChild(example_container_list)
|
||||
example_container_list = doc.createElement("exampleContainerList")
|
||||
sense_xml.appendChild(example_container_list)
|
||||
|
||||
for example in sense.examples:
|
||||
example_container = example.export(doc, example_container_list)
|
||||
|
||||
translation_container_list = example_container.querySelector("exampleContainer > translationContainerList")
|
||||
if translation_container_list is None:
|
||||
translation_container_list = doc.createElement("translationContainerList")
|
||||
example_container.appendChild(translation_container_list)
|
||||
|
||||
example_container = example.export(doc)
|
||||
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)
|
||||
|
||||
return sense_xml
|
||||
|
||||
def export_translation_list(doc, py_parent, xml_parent):
|
||||
for cidx, cluster in enumerate(py_parent.translations):
|
||||
for translation in cluster:
|
||||
translation_container = export_translation(doc, translation, xml_parent)
|
||||
translation_container = export_translation(doc, translation)
|
||||
translation_container.setAttribute("cluster", str(cidx + 1))
|
||||
# xml_parent.appendChild(translation_container)
|
||||
xml_parent.appendChild(translation_container)
|
||||
|
||||
|
||||
def export_translation(doc, translation, xml_parent):
|
||||
translation_xml = translation.original_xml if translation.original_xml != None else doc.createElement("translationContainer")
|
||||
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)
|
||||
def export_translation(doc, translation):
|
||||
translation_xml = doc.createElement("translationContainer")
|
||||
translation_xml.appendChild(_export_label_list(doc, translation.tags))
|
||||
|
||||
actual_t = doc.createElement("translation")
|
||||
actual_t.textContent = translation.translation
|
||||
actual_t.setAttribute("targetLang", translation.targetLang)
|
||||
|
||||
|
@ -206,43 +160,30 @@ def export_translation(doc, translation, xml_parent):
|
|||
|
||||
if translation.source:
|
||||
actual_t.setAttribute("source", translation.source)
|
||||
translation_xml.appendChild(actual_t)
|
||||
|
||||
if len(translation.explanationList) > 0 :
|
||||
_export_explanation_list(doc, translation.explanationList, translation_xml)
|
||||
explanationList = _export_explanation_list(doc, translation.explanationList)
|
||||
translation_xml.appendChild(explanationList)
|
||||
|
||||
|
||||
|
||||
return translation_xml
|
||||
|
||||
def _export_explanation_list(doc, lst, xml_parent):
|
||||
result = xml_parent.querySelector("explanationList")
|
||||
if result is None:
|
||||
result = doc.createElement("explanationList")
|
||||
xml_parent.appendChild(result)
|
||||
|
||||
def _export_explanation_list(doc, lst):
|
||||
result = doc.createElement('explanationList')
|
||||
for explanation in lst:
|
||||
result.appendChild(explanation.export(doc))
|
||||
result.appendChild(explanation.export(doc))
|
||||
|
||||
def _export_label_list(doc, lst, xml_parent):
|
||||
result = xml_parent.querySelector("labelList")
|
||||
if result is None:
|
||||
result = doc.createElement("labelList")
|
||||
xml_parent.appendChild(result)
|
||||
|
||||
for key, value, idx in lst:
|
||||
|
||||
key, value = export_tag(key, value)
|
||||
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.setAttribute('type', key)
|
||||
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
|
||||
def _export_label_list(doc, lst):
|
||||
result = doc.createElement("labelList")
|
||||
for key, value in lst:
|
||||
key, value = export_tag(key, value)
|
||||
|
||||
label_el = doc.createElement("label")
|
||||
label_el.textContent = value
|
||||
label_el.setAttribute('type', key)
|
||||
result.appendChild(label_el)
|
||||
return result
|
||||
|
|
|
@ -24,32 +24,33 @@ def build_structure_conversions():
|
|||
if line[1] == "struktura":
|
||||
continue
|
||||
|
||||
vto_structure = line[1].strip().split(">")[1].split("<")[0]
|
||||
vto_name = line[2].strip()
|
||||
vto_id = line[4].strip()
|
||||
vto_id = line[6].strip()
|
||||
|
||||
if 0 in (len(vto_name), len(vto_id)):
|
||||
continue
|
||||
|
||||
vfrom = "^" + line[0].replace("?", "\?").replace("%s", "([a-zA-Z螚ȎŠ-]+)") + "$"
|
||||
structure_conversions.append((__new__(RegExp(vfrom, 'u')), vto_name, vto_id))
|
||||
structure_conversions.append((__new__(RegExp(vfrom, 'u')), vto_name, vto_structure, vto_id))
|
||||
|
||||
|
||||
def convert_structure(structure, type):
|
||||
if structure_conversions is None:
|
||||
build_structure_conversions()
|
||||
|
||||
for vfrom, vto_name, vto_id in structure_conversions:
|
||||
for vfrom, vto_name, vto_structure, vto_id in structure_conversions:
|
||||
match = structure.match(vfrom)
|
||||
# fix for ids 65, 66, 67 which instead matched with 64
|
||||
if match and vto_id == '64' and '-s' in type:
|
||||
# fix for ids 106, 107, 44 which instead matched with 30
|
||||
if match and vto_id == '30' and '-s' in type:
|
||||
vto_name = 's0-vp-s0'
|
||||
vto_id = '65'
|
||||
elif match and vto_id == '64' and '-g' in type:
|
||||
vto_id = '106'
|
||||
elif match and vto_id == '30' and '-g' in type:
|
||||
vto_name = 'gg-vp-gg'
|
||||
vto_id = '66'
|
||||
elif match and vto_id == '64' and '-r' in type:
|
||||
vto_id = '107'
|
||||
elif match and vto_id == '30' and '-r' in type:
|
||||
vto_name = 'r-vp-r'
|
||||
vto_id = '67'
|
||||
vto_id = '44'
|
||||
|
||||
if match:
|
||||
# we need to remove replace alias here as we want to use javascript's one
|
||||
|
@ -57,7 +58,7 @@ def convert_structure(structure, type):
|
|||
result = structure.replace(vfrom, vto_name).strip()
|
||||
__pragma__('alias', 'replace', "py_replace")
|
||||
|
||||
return result, vto_id
|
||||
return result, vto_structure, vto_id
|
||||
|
||||
window.console.log("Unknown structure: ", structure)
|
||||
return 'N/A', '/'
|
||||
|
|
|
@ -4,10 +4,8 @@ from browser import document
|
|||
def generic_list_getter():
|
||||
result = []
|
||||
for input_el in document.getElementsByClassName("list-adder-input"):
|
||||
result_candidate = {"value": input_el.value}
|
||||
if input_el.hasAttribute("data-id"):
|
||||
result_candidate.id = int(input_el.getAttribute("data-id"))
|
||||
if result_candidate.value != "":
|
||||
result_candidate = input_el.value
|
||||
if result_candidate != "":
|
||||
result.append(result_candidate)
|
||||
return result
|
||||
|
||||
|
@ -15,19 +13,16 @@ def generic_list_getter():
|
|||
def double_list_getter(firstParameter, secondParameter, allowEmptyField = False):
|
||||
result = []
|
||||
for row in document.getElementsByClassName("double-list-row"):
|
||||
output = {}
|
||||
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"))
|
||||
firstValue = row.querySelector("." + firstParameter + "-input").value
|
||||
secondValue = row.querySelector("." + secondParameter + "-input").value
|
||||
|
||||
if (allowEmptyField is False and '' in [output[firstParameter], output[secondParameter]]):
|
||||
if (allowEmptyField is False and '' in [firstValue, secondValue]):
|
||||
continue
|
||||
|
||||
if (allowEmptyField is True and all('' == value or value.isspace() for value in [output[firstParameter], output[secondParameter]])):
|
||||
if (allowEmptyField is True and all('' == value or value.isspace() for value in [firstValue, secondValue])):
|
||||
continue
|
||||
|
||||
result.append(output)
|
||||
result.append({firstParameter: firstValue, secondParameter: secondValue})
|
||||
|
||||
return result
|
||||
|
||||
|
@ -38,7 +33,6 @@ def label_list_getter():
|
|||
ltype = row.querySelector(".label-type")
|
||||
lvalue = row.querySelector(".label-value")
|
||||
lother = row.querySelector(".label-value-other")
|
||||
idx = int(row.getAttribute("data-id")) if row.hasAttribute("data-id") else -1
|
||||
|
||||
if lother is None:
|
||||
continue
|
||||
|
@ -50,7 +44,7 @@ def label_list_getter():
|
|||
if not value:
|
||||
continue
|
||||
|
||||
result.append((ltype.textContent, value, idx))
|
||||
result.append((ltype.textContent, value))
|
||||
|
||||
kontrastivno = document.getElementById("kontrastivno-input").checked;
|
||||
if kontrastivno:
|
||||
|
|
|
@ -21,9 +21,7 @@ class DeleteRelatedEntries(DeleteVariants):
|
|||
|
||||
class DeleteHomonymy(NoReset):
|
||||
def update_model(self, model):
|
||||
for el in document.getElementsByClassName("name-input"):
|
||||
el.value = ""
|
||||
for el in document.getElementsByClassName("value-input"):
|
||||
for el in document.getElementsByClassName("list-adder-input"):
|
||||
el.value = ""
|
||||
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ class EditExampleText(Message):
|
|||
if example.newly_created:
|
||||
example.newly_created = False
|
||||
sense.examples.append(example)
|
||||
console.log(example)
|
||||
|
||||
idx = 0
|
||||
for txt in document.getElementsByClassName("example-component-text"):
|
||||
example.components[idx].text = txt.value
|
||||
|
|
|
@ -14,59 +14,45 @@ class SenseMoveUp(DataChgClickMessage):
|
|||
def update_model(self, model):
|
||||
sense = self.get_arg(0, Sense)
|
||||
sidx = _get_sense_idx(sense, model)
|
||||
|
||||
|
||||
assert(sidx >= 0)
|
||||
if sidx == 0:
|
||||
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]
|
||||
|
||||
|
||||
class SenseMoveDown(DataChgClickMessage):
|
||||
def update_model(self, model):
|
||||
sense = self.get_arg(0, Sense)
|
||||
sidx = _get_sense_idx(sense, model)
|
||||
|
||||
|
||||
assert(sidx >= 0)
|
||||
if sidx == len(model.senses) - 1:
|
||||
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]
|
||||
|
||||
|
||||
|
||||
|
||||
class SenseBin(DataChgClickMessage):
|
||||
def update_model(self, model):
|
||||
sense = self.get_arg(0, Sense)
|
||||
sidx = _get_sense_idx(sense, model)
|
||||
|
||||
|
||||
assert(sidx >= 0)
|
||||
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):
|
||||
def on_event(self, event):
|
||||
super().on_event(event)
|
||||
self.event_copy = event
|
||||
|
||||
|
||||
def update_model(self, model):
|
||||
sense = self.get_arg(0, Sense)
|
||||
new_example = Example.new_multiword()
|
||||
|
||||
|
||||
# open up an edit example dialog
|
||||
delayed_msg(ShowExampleEdit, self.event_copy, 0, new_example, sense)
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -17,14 +17,6 @@ class EditSenseLabel(Message):
|
|||
sense = self.get_arg(0, Sense)
|
||||
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):
|
||||
def update_model(self, model):
|
||||
|
@ -51,14 +43,14 @@ class AddToLabelList(NoReset):
|
|||
class AddSense(Message):
|
||||
def update_model(self, model):
|
||||
sense = Sense()
|
||||
sense.definitions.append({"type": "indicator", "value": "New Sense"})
|
||||
sense.definition = {"indicator": "New Sense"}
|
||||
model.entry.senses.append(sense)
|
||||
|
||||
|
||||
class EditSenseDefinition(QuestionMessage):
|
||||
def update_model(self, model):
|
||||
sense = self.get_arg(0, Sense)
|
||||
sense.definitions[0].value = self.new_text
|
||||
sense.definition["indicator"] = self.new_text
|
||||
|
||||
|
||||
class EditComment(QuestionMessage):
|
||||
|
@ -94,36 +86,23 @@ class DoChosenExamples(Message):
|
|||
class EditVariants(Message):
|
||||
def update_model(self, model):
|
||||
variants = common_accessors.generic_list_getter()
|
||||
update_entries(variants, "head variantList variant", model)
|
||||
model.entry.variants = variants
|
||||
|
||||
class EditHomonymy(Message):
|
||||
def update_model(self, model):
|
||||
homonymy = common_accessors.double_list_getter("value", "name")
|
||||
|
||||
update_entries(homonymy, "head headword homonymy homonymyFeature", model)
|
||||
|
||||
model.entry.homonymy = homonymy
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
class EditEntryLabels(Message):
|
||||
def update_model(self, model):
|
||||
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
|
||||
|
||||
|
||||
|
@ -139,13 +118,3 @@ class ExampleClusterAdd(DataChgClickMessage):
|
|||
example = self.get_arg(0, Example)
|
||||
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
|
||||
|
|
|
@ -59,7 +59,8 @@ class SkeCollocation:
|
|||
def __init__(self, data):
|
||||
self.word = data.word
|
||||
self.frequency = data.count
|
||||
self.structure_name, self.structure_id = convert_structure(data.gramrel, data.lempos)
|
||||
self.gramrel = data.gramrel
|
||||
self.structure_name, self.structure, self.structure_id = convert_structure(data.gramrel, data.lempos)
|
||||
|
||||
self.other = {"score": data.score, "cm": data.cm}
|
||||
|
||||
|
@ -102,13 +103,28 @@ def match_gf2_examples(data, *args):
|
|||
xhr.send(to_send)
|
||||
|
||||
|
||||
def make_cql_query(ske_index, search_term, pos):
|
||||
cql_pos= {
|
||||
"samostalnik": ("S.*", "-s"),
|
||||
"glagol": ("G.*", "-g"),
|
||||
"pridevnik": ("P.*", "-p"),
|
||||
"prislov": ("R.*", "-r"),
|
||||
"zaimek": ("Z.*", "-z")
|
||||
}
|
||||
|
||||
if ske_index == 0:
|
||||
return "[ lemma=\"{0}\" & tag=\"{1}\" ]".format(search_term, cql_pos[pos][0])
|
||||
else:
|
||||
return search_term + cql_pos[pos][1]
|
||||
|
||||
|
||||
class SkeModal(ClickMessage):
|
||||
def on_event(self, event):
|
||||
# event could be data if this is the return from external library
|
||||
if type(event) in [list, int]:
|
||||
self.add_arg(event)
|
||||
else:
|
||||
if len(self._args) < 4:
|
||||
if len(self._args) < 5:
|
||||
self.add_arg(None)
|
||||
super().on_event(event)
|
||||
|
||||
|
@ -116,18 +132,20 @@ class SkeModal(ClickMessage):
|
|||
page_num = self.get_arg(0, int)
|
||||
search_term = self.get_arg(1, str)
|
||||
ske_index = self.get_arg(2, int)
|
||||
ske_pos_query = self.get_arg(3, str)
|
||||
ske_lookup = model.ske.url_for_kind_index(ske_index)
|
||||
|
||||
next_message = msg(SkeModal, page_num, search_term, ske_index)
|
||||
next_message = msg(SkeModal, page_num, search_term, ske_index, ske_pos_query)
|
||||
|
||||
# could be none if empty
|
||||
data = self.get_arg(3)
|
||||
data = self.get_arg(4)
|
||||
|
||||
if data is None:
|
||||
params = {"additional_refs": "s.id,p.id",
|
||||
"page_num": page_num,
|
||||
"error_callback": next_message,
|
||||
"data_parser": get_parser(ske_index)}
|
||||
"data_parser": get_parser(ske_index),
|
||||
"querytype": ske_pos_query}
|
||||
|
||||
gdex = get_preference("ske_gdex")
|
||||
if gdex:
|
||||
|
@ -136,15 +154,36 @@ class SkeModal(ClickMessage):
|
|||
return
|
||||
params["gdex"] = gdex
|
||||
|
||||
# enable CQL query
|
||||
if ske_pos_query is not "simple":
|
||||
search_term_old = search_term
|
||||
search_term = make_cql_query(ske_index, search_term, ske_pos_query)
|
||||
|
||||
model.ske.request(search_term, next_message, ske_lookup, params)
|
||||
|
||||
search_term = search_term_old
|
||||
|
||||
elif type(data) is list:
|
||||
window.console.log(data)
|
||||
# check if gf2 examples are loaded or not
|
||||
if not data[0].gf2_check and type(data[0]) is SkeExample:
|
||||
# we get the data, we have to match it with available data on our gf2 examples API
|
||||
match_gf2_examples(data, page_num, search_term, ske_index)
|
||||
|
||||
match_gf2_examples(data, page_num, search_term, ske_index, ske_pos_query)
|
||||
elif type(data[0]) is SkeCollocation:
|
||||
# filtering, grouping and sorting data
|
||||
data.sort(key= lambda x: float(x.other["score"]), reverse=True)
|
||||
_data = []
|
||||
while len(data) > 0:
|
||||
max_item = data.pop(0) # max(data, key= lambda x: x.other["score"])
|
||||
_data.append(max_item)
|
||||
for item in data:
|
||||
if "N/A" in item.structure_name:
|
||||
data.remove(item)
|
||||
elif item.structure_name.strip() == max_item.structure_name.strip():
|
||||
_data.append(item)
|
||||
for delete_item in _data:
|
||||
if delete_item in data:
|
||||
data.remove(delete_item)
|
||||
data = _data
|
||||
model.modal_set(lambda: modals.ske_list(
|
||||
search_term, data, page_num, model.entry.senses, model.ske.request_kinds))
|
||||
|
||||
|
@ -155,7 +194,7 @@ class SkeModal(ClickMessage):
|
|||
class SkeModalGf2Update(SkeModal):
|
||||
def on_event(self, event):
|
||||
response_data = window.JSON.parse(event.target.response)
|
||||
data = self.get_arg(3)
|
||||
data = self.get_arg(4)
|
||||
|
||||
data_dict = {}
|
||||
for example in data:
|
||||
|
@ -191,6 +230,7 @@ class SearchInSkeModal(SkeModal):
|
|||
self.add_arg(int(document.getElementById("ske-page-num").value))
|
||||
self.add_arg(document.getElementById("ske-search").value)
|
||||
self.add_arg(document.getElementById("ske-select").selectedIndex)
|
||||
self.add_arg(document.getElementById("ske-pos-query").value)
|
||||
super().on_event(event)
|
||||
|
||||
|
||||
|
@ -238,7 +278,7 @@ class SkeInsert(DataChgClickMessage):
|
|||
|
||||
lex_mid = ComponentLexeme()
|
||||
lex_mid.text = example["mid"]
|
||||
lex_mid.role = "collocation"
|
||||
lex_mid.role = "headword"
|
||||
|
||||
lex_right = ComponentLexeme()
|
||||
lex_right.text = example["right"]
|
||||
|
@ -257,17 +297,45 @@ class SkeInsert(DataChgClickMessage):
|
|||
new_collocation.inner.other_attributes["frequency"] = example.frequency
|
||||
new_collocation.inner.type = "collocation"
|
||||
|
||||
lex_left = ComponentLexeme()
|
||||
lex_left.text = ""
|
||||
lex_left.role = None
|
||||
|
||||
lex_mid = ComponentLexeme()
|
||||
lex_mid.text = example.word
|
||||
lex_mid.role = "collocation"
|
||||
|
||||
lex_right = ComponentLexeme()
|
||||
lex_right.text = ""
|
||||
lex_right.role = None
|
||||
|
||||
new_collocation.components.extend([lex_left, lex_mid, lex_right])
|
||||
headword = document.getElementById("ske-search").value
|
||||
lexemes = []
|
||||
structure_name = example.structure_name.split("-")
|
||||
gramrel = example.gramrel.split("_")
|
||||
structure = example.structure.split(" ")
|
||||
structure.append("") # Bad fix: we have to add something for structure l-gg-ggn
|
||||
|
||||
for i in range(len(structure_name)):
|
||||
lex = ComponentLexeme()
|
||||
structure[i] = structure[i].replace("Inf-", "")
|
||||
|
||||
# take care of negations "ne"
|
||||
if "Neg-" in structure[i]:
|
||||
structure[i] = structure[i].replace("Neg-", "")
|
||||
negation_flag = True
|
||||
n_lex = ComponentLexeme()
|
||||
n_lex.text = "ne"
|
||||
n_lex.role = "other"
|
||||
lexemes.append(n_lex)
|
||||
|
||||
if structure[i] is "":
|
||||
continue # skipping bcs of fix
|
||||
elif "Vez-gbz" in structure[i]:
|
||||
lex.text = "je"
|
||||
lex.role = "other"
|
||||
elif structure_name[i] in ["d", "vd", "zp"]:
|
||||
lex.text = gramrel[i]
|
||||
lex.text = lex.text.replace("-d", "").replace("%", "")
|
||||
lex.role = "other"
|
||||
elif structure_name[i] is "vp":
|
||||
lex.text = structure[i]
|
||||
lex.role = "other"
|
||||
elif structure[i][0] in ["S", "G", "P", "R"]:
|
||||
lex.text = headword
|
||||
lex.role = "headword"
|
||||
else:
|
||||
lex.text = example.word
|
||||
lex.role = "collocate"
|
||||
lexemes.append(lex)
|
||||
|
||||
new_collocation.components.extend(lexemes)
|
||||
return new_collocation
|
||||
|
|
|
@ -14,7 +14,6 @@ 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)
|
||||
self.translation.explanationList = []
|
||||
|
@ -22,19 +21,10 @@ class EditTranslation(DataChgClickMessage):
|
|||
explanation = Explanation()
|
||||
explanation.value = entry.value
|
||||
explanation.language = entry.language
|
||||
explanation.original_xml = entry.original_xml if entry.original_xml != None else None
|
||||
self.translation.explanationList.append(explanation)
|
||||
|
||||
# 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!
|
||||
if self.translation.is_empty():
|
||||
model.entry.remove_translation(self.translation)
|
||||
|
|
|
@ -63,7 +63,7 @@ class Data:
|
|||
return None
|
||||
|
||||
def overwrite_with_copy(self):
|
||||
for key, value in dict(self).items():
|
||||
for key, value in dict(self._copy).items():
|
||||
# skip functions and _copy
|
||||
if key == "_copy" or type(value) is None:
|
||||
continue
|
||||
|
|
|
@ -26,8 +26,7 @@ class Entry(Data):
|
|||
self.original_xml = None
|
||||
|
||||
def import_xml(self, entry_xml):
|
||||
console.log(entry_xml)
|
||||
self.original_xml = entry_xml
|
||||
self.original_xml = entry_xml.cloneNode(True)
|
||||
status = entry_xml.querySelector("head status")
|
||||
|
||||
headword = entry_xml.querySelector("head headword lemma")
|
||||
|
@ -40,9 +39,9 @@ class Entry(Data):
|
|||
self.headword_audio = headword.getAttribute("audio") if headword and headword.hasAttribute("audio") else None
|
||||
self.grammar = grammar.textContent if grammar else ""
|
||||
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 = [{"value": re.textContent, "id": index} for index, re in enumerate(entry_xml.querySelectorAll("head relatedEntryList relatedEntry"))]
|
||||
self.variants = [v.textContent for v in 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.related_entries = [re.textContent for re in entry_xml.querySelectorAll("head relatedEntryList relatedEntry")]
|
||||
|
||||
lex_unit = entry_xml.querySelector("lexical_unit lexeme,lexicalUnit lexeme")
|
||||
if lex_unit:
|
||||
|
@ -55,13 +54,12 @@ class Entry(Data):
|
|||
self.measure["type"] = measure.getAttribute("type")
|
||||
self.measure["text"] = measure.textContent
|
||||
|
||||
self.labels = import_label_list("head labelList label", self.original_xml)
|
||||
self.labels = import_label_list("head labelList label", entry_xml)
|
||||
|
||||
for i, sense_xml in enumerate(entry_xml.querySelectorAll("body senseList sense")):
|
||||
sense = Sense()
|
||||
sense.import_xml(sense_xml, i)
|
||||
self.senses.append(sense)
|
||||
sense_xml.remove()
|
||||
|
||||
|
||||
def view(self, model):
|
||||
|
@ -98,7 +96,7 @@ class Entry(Data):
|
|||
if len(self.variants) == 0:
|
||||
view_buttons.append(buttons[0])
|
||||
else:
|
||||
view_table.append((buttons[0], ", ".join(v.value for v in self.variants)))
|
||||
view_table.append((buttons[0], ", ".join(self.variants)))
|
||||
|
||||
if len(self.homonymy) == 0:
|
||||
view_buttons.append(buttons[4])
|
||||
|
@ -108,7 +106,7 @@ class Entry(Data):
|
|||
if len(self.related_entries) == 0:
|
||||
view_buttons.append(buttons[1])
|
||||
else:
|
||||
view_table.append((buttons[1], ", ".join(re.value for re in self.related_entries)))
|
||||
view_table.append((buttons[1], ", ".join(self.related_entries)))
|
||||
|
||||
if len(self.labels) == 0:
|
||||
view_buttons.append(buttons[2])
|
||||
|
@ -143,3 +141,4 @@ class Entry(Data):
|
|||
if translation in cluster:
|
||||
cluster.remove(translation)
|
||||
return
|
||||
|
||||
|
|
|
@ -11,10 +11,8 @@ class ComponentLexeme(Data):
|
|||
self.text = ""
|
||||
self.role = ""
|
||||
self.no_space = False
|
||||
self.original_xml = None
|
||||
|
||||
def import_xml(self, xml):
|
||||
self.original_xml = xml.cloneNode(True)
|
||||
if xml.nodeName == "#text":
|
||||
self.text = xml.data
|
||||
self.role = None
|
||||
|
@ -27,7 +25,6 @@ class ComponentLexeme(Data):
|
|||
for oth_attr in ["lexeme_id", "lexical_unit_lexeme_id", "slolex", "kol", "sloleks"]:
|
||||
if xml.hasAttribute(oth_attr):
|
||||
self.other_attributes[oth_attr] = xml.getAttribute(oth_attr)
|
||||
xml.remove()
|
||||
|
||||
def isValid(self):
|
||||
return len(self.text) > 0
|
||||
|
@ -35,8 +32,7 @@ class ComponentLexeme(Data):
|
|||
def export(self, doc):
|
||||
if self.role is None:
|
||||
return doc.createTextNode(self.text)
|
||||
result = self.original_xml if self.original_xml is not None else doc.createElement("comp")
|
||||
|
||||
result = doc.createElement("comp")
|
||||
result.setAttribute("role", self.role)
|
||||
result.textContent = self.text
|
||||
|
||||
|
|
|
@ -3,17 +3,14 @@ from lib.snabbdom import h
|
|||
class CorpusExample:
|
||||
def __init__(self):
|
||||
self.other_attributes = {}
|
||||
self.original_xml = None
|
||||
|
||||
def import_xml(self, example_xml):
|
||||
for oth_attr in ["example_id", "modified", "lexical_unit_id", "audio"]:
|
||||
if example_xml.hasAttribute(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):
|
||||
result = self.original_xml if self.original_xml is not None else doc.createElement("corpusExample")
|
||||
result = doc.createElement("corpusExample")
|
||||
if modified:
|
||||
result.setAttribute("modified", "true")
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ from model.example_clusters import ExampleClusters
|
|||
|
||||
class Example(Data):
|
||||
def __init__(self):
|
||||
self.original_xml = None
|
||||
self.translations = []
|
||||
self.inner = None
|
||||
self.components = []
|
||||
|
@ -42,20 +41,20 @@ class Example(Data):
|
|||
|
||||
def import_xml(self, example_xml):
|
||||
self.translations = from_container_list(example_xml.querySelectorAll("translationContainerList translationContainer"))
|
||||
self.original_xml = example_xml.cloneNode(True)
|
||||
|
||||
if example_xml.hasAttribute("modified"):
|
||||
self.edited = example_xml.getAttribute("modified") == "true"
|
||||
|
||||
inner_xml = self.original_xml.querySelector("corpusExample")
|
||||
inner_xml = example_xml.querySelector("corpusExample")
|
||||
if inner_xml is not None:
|
||||
self.inner = CorpusExample()
|
||||
else:
|
||||
inner_xml = self.original_xml.querySelector("multiwordExample")
|
||||
inner_xml = example_xml.querySelector("multiwordExample")
|
||||
self.inner = MultiwordExample()
|
||||
|
||||
self.inner.import_xml(inner_xml)
|
||||
|
||||
for idx, comp_xml in enumerate(self.inner.original_xml.childNodes):
|
||||
for idx, comp_xml in enumerate(inner_xml.childNodes):
|
||||
comp = ComponentLexeme()
|
||||
comp.import_xml(comp_xml)
|
||||
if comp.isValid():
|
||||
|
@ -63,10 +62,11 @@ class Example(Data):
|
|||
|
||||
self.check_multiword_components()
|
||||
|
||||
def export(self, doc, xml_parent):
|
||||
def export(self, doc):
|
||||
self.check_multiword_components()
|
||||
result = self.original_xml if self.original_xml != None else doc.createElement("exampleContainer")
|
||||
xml_parent.appendChild(result)
|
||||
|
||||
result = doc.createElement("exampleContainer")
|
||||
|
||||
inner = self.inner.export(doc, self.edited)
|
||||
# TODO: bad quick fix
|
||||
for comp in self.components:
|
||||
|
|
|
@ -6,10 +6,8 @@ class MultiwordExample:
|
|||
self.other_attributes = {}
|
||||
self.cluster = -1
|
||||
self.type = None
|
||||
self.original_xml = None
|
||||
|
||||
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"]:
|
||||
if example_xml.hasAttribute(oth_attr):
|
||||
self.other_attributes[oth_attr] = example_xml.getAttribute(oth_attr)
|
||||
|
@ -18,10 +16,7 @@ class MultiwordExample:
|
|||
|
||||
if example_xml.hasAttribute("type"):
|
||||
self.type = example_xml.getAttribute("type")
|
||||
|
||||
|
||||
example_xml.remove()
|
||||
|
||||
|
||||
@staticmethod
|
||||
def _determine_cluster_number(example_xml):
|
||||
if not example_xml.hasAttribute("cluster"):
|
||||
|
@ -32,8 +27,8 @@ class MultiwordExample:
|
|||
return cluster
|
||||
|
||||
def export(self, doc, _modified):
|
||||
result = self.original_xml if self.original_xml is not None else doc.createElement("multiwordExample")
|
||||
# result = doc.createElement("multiwordExample")
|
||||
result = doc.createElement("multiwordExample")
|
||||
|
||||
for key, value in self.other_attributes.items():
|
||||
result.setAttribute(key, value)
|
||||
|
||||
|
|
|
@ -7,15 +7,14 @@ class Explanation(Data):
|
|||
def __init__(self):
|
||||
self.value = ""
|
||||
self.language = ""
|
||||
self.original_xml = None
|
||||
|
||||
def import_dom(self, explanation_xml):
|
||||
self.original_xml = explanation_xml.cloneNode(True)
|
||||
self.value = explanation_xml.textContent if explanation_xml else ""
|
||||
self.language = explanation_xml.getAttribute("language") if explanation_xml.hasAttribute("language") else ""
|
||||
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 = self.original_xml if self.original_xml != None else doc.createElement("explanation")
|
||||
result = doc.createElement("explanation")
|
||||
result.textContent = self.value
|
||||
if self.language != "": result.setAttribute('language', self.language)
|
||||
|
||||
|
|
|
@ -11,34 +11,25 @@ from view.utils import clean_label
|
|||
class Sense(Data):
|
||||
def __init__(self):
|
||||
self.original_idx = -1
|
||||
self.original_xml = None
|
||||
self.definitions = []
|
||||
self.definition = {}
|
||||
self.labels = []
|
||||
self.translations = []
|
||||
self.examples = []
|
||||
|
||||
def import_xml(self, sense_xml, idx):
|
||||
self.original_idx = idx
|
||||
self.original_xml = sense_xml.cloneNode(True)
|
||||
|
||||
for definition in self.original_xml.querySelectorAll("definitionList definition"):
|
||||
definition_object = {}
|
||||
definition_object.type = definition.getAttribute("type")
|
||||
definition_object.value = definition.textContent
|
||||
definition_object.original_xml = definition
|
||||
definition.remove()
|
||||
self.definitions.append(definition_object)
|
||||
for definition in sense_xml.querySelectorAll("definitionList definition"):
|
||||
key = definition.getAttribute("type")
|
||||
self.definition[key] = definition.textContent
|
||||
|
||||
self.labels = import_label_list("sense > labelList label", self.original_xml)
|
||||
self.labels = import_label_list("sense > labelList label", sense_xml)
|
||||
self.translations = from_container_list(
|
||||
self.original_xml.querySelectorAll('sense > translationContainerList translationContainer'))
|
||||
for example_xml in self.original_xml.querySelectorAll("exampleContainerList exampleContainer"):
|
||||
sense_xml.querySelectorAll('sense > translationContainerList translationContainer'))
|
||||
for example_xml in sense_xml.querySelectorAll("exampleContainerList exampleContainer"):
|
||||
example = Example()
|
||||
example.import_xml(example_xml)
|
||||
self.examples.append(example)
|
||||
example_xml.remove()
|
||||
|
||||
console.log(self.original_xml)
|
||||
|
||||
|
||||
def merge_labels(self):
|
||||
|
@ -53,7 +44,7 @@ class Sense(Data):
|
|||
h("div.sense", {}, [
|
||||
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-definition", { "on": { "click": M.msg(M.ShowSenseDefinitionEdit, self) }}, ", ".join(d.value for d in self.definitions)),
|
||||
h("span.sense-definition", { "on": { "click": M.msg(M.ShowSenseDefinitionEdit, self) }}, self.definition["indicator"]),
|
||||
h("div", {}, View.view_translations(self.translations, self, model)),
|
||||
h("div", {}, examples)])])
|
||||
return result
|
||||
|
|
|
@ -35,12 +35,12 @@ STYLE_SECTIONS = [("registrske", "register"),
|
|||
|
||||
def import_label_list(selector, xml_element):
|
||||
result = []
|
||||
for index, tag_xml in enumerate(xml_element.querySelectorAll(selector)):
|
||||
for tag_xml in xml_element.querySelectorAll(selector):
|
||||
t_type = tag_xml.getAttribute("type")
|
||||
t_value = tag_xml.textContent
|
||||
|
||||
|
||||
t_type, t_value = import_tag(t_type, t_value)
|
||||
result.append((t_type, t_value, index))
|
||||
result.append((t_type, t_value))
|
||||
return result
|
||||
|
||||
|
||||
|
@ -50,14 +50,14 @@ def import_tag(key, value):
|
|||
# simmilar for "stilne"
|
||||
# if english, than translate and change style-xxx for stilne
|
||||
# for value, just handle if some bad "-- xxx" stuff is in xml
|
||||
|
||||
|
||||
if key in SLO2ENG_TAGS:
|
||||
pass
|
||||
elif key in ("stilne", "style"):
|
||||
key = "stilne"
|
||||
elif key in ENG2SLO_TAGS:
|
||||
key = ENG2SLO_TAGS[key]
|
||||
|
||||
|
||||
# handle stilne-xxx stuff
|
||||
if "-" in key:
|
||||
key = key.split("-")[0]
|
||||
|
@ -65,15 +65,15 @@ def import_tag(key, value):
|
|||
window.console.log("Uknown tag :(", key, value)
|
||||
# using some default
|
||||
key = TAGS.keys()[0]
|
||||
|
||||
|
||||
# this should not happen, but maybe there was a bug...
|
||||
value = value.replace("--", "").strip()
|
||||
|
||||
|
||||
for tag_key in TAGS.keys():
|
||||
for possible_value in TAGS[tag_key]:
|
||||
if value == possible_value or "-- " + value == possible_value:
|
||||
return key, possible_value
|
||||
|
||||
|
||||
# not found, must be manually inputted
|
||||
return key, value
|
||||
|
||||
|
@ -83,18 +83,18 @@ def export_tag(key, value):
|
|||
arr = TAGS["stilne"]
|
||||
key = "style"
|
||||
value_idx = arr.index(value)
|
||||
|
||||
|
||||
if value_idx >= 0:
|
||||
for sec_slo, sec_eng in reversed(STYLE_SECTIONS):
|
||||
idx = arr.index(sec_slo)
|
||||
if idx < value_idx:
|
||||
key = "style-" + sec_eng
|
||||
break
|
||||
|
||||
|
||||
else:
|
||||
key = SLO2ENG_TAGS[key]
|
||||
|
||||
|
||||
value = value.replace("--", "").strip()
|
||||
return key, value
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -20,8 +20,6 @@ def from_container_list(translation_list_container_xml):
|
|||
t = Translation()
|
||||
t.import_xml(translation_xml)
|
||||
translations.append((num_cluster, t))
|
||||
translation_xml.remove()
|
||||
|
||||
|
||||
result = [[] for _ in range(max_num_cluster)]
|
||||
for clusterNum, translation in translations:
|
||||
|
@ -32,7 +30,6 @@ def from_container_list(translation_list_container_xml):
|
|||
|
||||
class Translation(Data):
|
||||
def __init__(self, translation_xml):
|
||||
self.original_xml = None
|
||||
self.translation = ""
|
||||
self.source = ""
|
||||
self.targetLang = ""
|
||||
|
@ -42,7 +39,6 @@ class Translation(Data):
|
|||
|
||||
def import_xml(self, translation_xml):
|
||||
translation = translation_xml.querySelector("translation")
|
||||
self.original_xml = translation_xml.cloneNode(True)
|
||||
|
||||
if translation:
|
||||
self.translation = translation.textContent
|
||||
|
@ -50,13 +46,13 @@ class Translation(Data):
|
|||
self.targetLang = translation.getAttribute("targetLang") if translation.hasAttribute("targetLang") else ""
|
||||
self.audio = translation.getAttribute("audio") if translation.hasAttribute("audio") else ""
|
||||
|
||||
explanationList = self.original_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)
|
||||
explanation_dom.remove()
|
||||
self.tags = import_label_list("labelList label", self.original_xml)
|
||||
|
||||
self.tags = import_label_list("labelList label", translation_xml)
|
||||
|
||||
def view(self, model):
|
||||
elements = []
|
||||
|
|
|
@ -42,19 +42,15 @@ def question(question, current_value):
|
|||
def generic_list_editor(title, element_list_getter):
|
||||
content = [h("p", {}, title)]
|
||||
for slabel in element_list_getter():
|
||||
idAttr = {"data-id": slabel.id} if slabel.id >= 0 else {}
|
||||
content.append(h("label", {}, [
|
||||
h("input.list-adder-input", {"props": {"type": "text", "value": slabel.value or slabel}, "attrs": idAttr}, "")]))
|
||||
|
||||
console.log(content)
|
||||
h("input.list-adder-input", {"props": {"type": "text", "value": slabel}}, "")]))
|
||||
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, element_list_getter)}}, "+"))
|
||||
return content
|
||||
|
||||
def homonymy_editor(title, current_labels):
|
||||
def split_line2(left, right, labelId):
|
||||
def split_line2(left, right):
|
||||
cls = "flex.two{}".format(".double-list-row")
|
||||
isId = {"attrs": {"data-id": labelId}} if labelId >= 0 else {}
|
||||
return h("div.{}".format(cls), isId, [
|
||||
return h("div.{}".format(cls), {}, [
|
||||
h("div.half", {}, left), h("div.half", {}, right)])
|
||||
|
||||
content = [h("p", {}, title)]
|
||||
|
@ -62,20 +58,19 @@ def homonymy_editor(title, current_labels):
|
|||
name = []
|
||||
value = []
|
||||
name.append(h("label", {"attrs": {"for": i}}, "Name:"))
|
||||
name.append(h("input.name-input", {"props": {"type": "text", "value": feature["name"], "id": i, "data-id": feature.id}}, ""))
|
||||
name.append(h("input.name-input", {"props": {"type": "text", "value": feature["name"], "id": i}}, ""))
|
||||
value.append(h("label", {"attrs": {"for": i + "-value"}}, "Value:"))
|
||||
value.append(h("input.value-input", {"props": {"type": "text", "value": feature["value"], "id": i + "-value"}}, ""))
|
||||
|
||||
content.append(split_line2(name, value, feature.id))
|
||||
content.append(split_line2(name, value))
|
||||
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, current_labels)}}, "+"))
|
||||
|
||||
return content
|
||||
|
||||
def explanation_editor(title, current_labels):
|
||||
def split_line2(left, right, labelId):
|
||||
def split_line2(left, right):
|
||||
cls = "flex.two{}".format(".double-list-row")
|
||||
isId = {"attrs": {"data-id": labelId}} if labelId >= 0 else {}
|
||||
return h("div.{}".format(cls), isId, [
|
||||
return h("div.{}".format(cls), {}, [
|
||||
h("div.four-fifth", {}, left), h("div.fifth", {}, right)])
|
||||
|
||||
content = [h("p", {}, title)]
|
||||
|
@ -87,7 +82,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, explanation.id))
|
||||
content.append(split_line2(value, language))
|
||||
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, current_labels)}}, "+"))
|
||||
|
||||
return content
|
||||
|
@ -95,13 +90,12 @@ def explanation_editor(title, current_labels):
|
|||
|
||||
|
||||
def label_list_editor(current_labels, add_label_message_class):
|
||||
def split_line3(left, center, right, labelId, is_llr=True):
|
||||
isId = {"attrs": {"data-id": labelId}} if labelId >= 0 else {}
|
||||
def split_line3(left, center, right, is_llr=True):
|
||||
cls = "flex.three{}".format(".label-list-row" if is_llr else "")
|
||||
return h("div.{}".format(cls), isId, [
|
||||
return h("div.{}".format(cls), {}, [
|
||||
h("span.third", {}, left), h("span.third", {}, center), h("span.third", {}, right)])
|
||||
|
||||
def dropdown_right(label_type, label, index):
|
||||
def dropdown_right(label_type, label):
|
||||
left = h("span.label-type", {}, label_type)
|
||||
|
||||
options = [h("option", {}, [])]
|
||||
|
@ -114,16 +108,17 @@ def label_list_editor(current_labels, add_label_message_class):
|
|||
{"props": {"type": "text", "value": right_value, "placeholder": "drugo"}},
|
||||
[])
|
||||
|
||||
return split_line3(left, center, right, index)
|
||||
return split_line3(left, center, right)
|
||||
|
||||
content = []
|
||||
kontrastivno = False
|
||||
for key, value, idx in current_labels:
|
||||
for key, value in current_labels:
|
||||
# we will show kontrastivno a bit differently
|
||||
if value == "kontrastivno":
|
||||
kontrastivno = True
|
||||
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
|
||||
def get_new_label_type():
|
||||
|
|
|
@ -40,9 +40,7 @@ def edit_sense_label(sense):
|
|||
|
||||
def edit_example(example, sense):
|
||||
example_original = example
|
||||
# example = example_original.deepcopy()
|
||||
# example = copy.deepcopy(example)
|
||||
# example.original_xml = example_original.original_xml.cloneNode(True)
|
||||
example = example_original.copy()
|
||||
|
||||
def role_msg(idx, role):
|
||||
return message.msg(message.ExampleRoleChange, example_original, idx, role)
|
||||
|
@ -66,14 +64,18 @@ def edit_example(example, sense):
|
|||
result.append(h("span.example-component-button.example-component-none",
|
||||
{"on": {"click": role_msg(idx, "none")}}, "N"))
|
||||
|
||||
result.extend([
|
||||
h("span.example-component-button",
|
||||
{"on": {"click": message.msg(message.ExampleComponentAdd, example_original, idx)}}, "+"),
|
||||
h("span.example-component-button",
|
||||
{"on": {"click": message.msg(message.ExampleComponentRemove, example_original, idx)}}, "-")])
|
||||
if "-" not in example.inner.other_attributes["structureName"]:
|
||||
result.extend([
|
||||
h("span.example-component-button",
|
||||
{"on": {"click": message.msg(message.ExampleComponentAdd, example_original, idx)}}, "+"),
|
||||
h("span.example-component-button",
|
||||
{"on": {"click": message.msg(message.ExampleComponentRemove, example_original, idx)}}, "-")])
|
||||
|
||||
return result
|
||||
|
||||
divs.append(h("div.flex.five.example-component", {}, [h("div.one-fifth", {}, "Struktura:"),
|
||||
h("div.three-fifth", {}, example.inner.other_attributes["structureName"])]))
|
||||
|
||||
for idx, component in enumerate(example.components):
|
||||
role_txt = component.role if component.role is not None else "none"
|
||||
color_class = ".example-component-" + role_txt
|
||||
|
@ -102,7 +104,6 @@ def edit_variants(entry):
|
|||
|
||||
def edit_homonymy(entry):
|
||||
hget = lambda: entry.copy().homonymy
|
||||
console.log(hget)
|
||||
content = homonymy_editor("Homonymy", hget)
|
||||
return modal_template(content, "Add or remove homonymy features", (message.EditHomonymy,), (message.DeleteHomonymy,))
|
||||
|
||||
|
@ -119,7 +120,7 @@ def edit_entry_labels(entry):
|
|||
|
||||
|
||||
def edit_sense_definition(sense):
|
||||
return modal_template(question("Edit sense definition", sense.definitions[0].value), "Sense definition", (message.EditSenseDefinition, sense))
|
||||
return modal_template(question("Edit sense definition", sense.definition["indicator"]), "Sense definition", (message.EditSenseDefinition, sense))
|
||||
|
||||
|
||||
def edit_comment(comment):
|
||||
|
@ -138,7 +139,7 @@ def do_chosen_examples(example_list, entry):
|
|||
|
||||
options = [h("p", {}, "Choose sense for examples")]
|
||||
for idx, sense in enumerate(entry.senses):
|
||||
text = "{}: {}".format(idx + 1, sense.definitions[0].value)
|
||||
text = "{}: {}".format(idx + 1, sense.definition["indicator"])
|
||||
id_ = "choose-example-{}".format(idx)
|
||||
|
||||
props = {"type": "radio", "name": "choose-example"}
|
||||
|
@ -180,6 +181,10 @@ def ske_list(search_term, data, page_num, senses, ske_kinds):
|
|||
"type": "number",
|
||||
"min": 1,
|
||||
"step": 1}}, "")]),
|
||||
h("label.fourth.ske-mid-input", {}, [
|
||||
h("select#ske-pos-query", {}, [h("option", {}, "{}".format(pos)) for pos in ["simple", "samostalnik", "glagol", "pridevnik", "prislov", "zaimek"]])
|
||||
]),
|
||||
|
||||
h("span.fourth.button.ske-right-button",
|
||||
{"on": {"click": message.msg(message.SearchInSkeModal)}}, "Isci")]),
|
||||
h("div.ske-list",
|
||||
|
@ -188,6 +193,6 @@ def ske_list(search_term, data, page_num, senses, ske_kinds):
|
|||
h("div.flex.three", {}, [
|
||||
h("span.third", {}, "Vstavi v:"),
|
||||
h("select#ske-sense-select.two-third", {}, [ h("option", {}, "{} {}".format(
|
||||
idx + 1, sense.definitions[0].value)) for idx, sense in enumerate(senses)])])]
|
||||
idx + 1, sense.definition["indicator"])) for idx, sense in enumerate(senses)])])]
|
||||
|
||||
return modal_template(contents, "SKE", (message.SkeInsert, data))
|
||||
|
|
|
@ -58,7 +58,7 @@ class View:
|
|||
def view_ske_button(model):
|
||||
return h(
|
||||
"span#ske-button.button.toggle",
|
||||
{ "on": {"click": msg(ShowSkeModal, 1, model.entry.headword, 0)} },
|
||||
{ "on": {"click": msg(ShowSkeModal, 1, model.entry.headword, 0, "simple")} },
|
||||
h("svg#ske-img", {
|
||||
"attrs": {
|
||||
"xmlns": "http://www.w3.org/2000/svg",
|
||||
|
|
Loading…
Reference in New Issue
Block a user