Compare commits

..

10 Commits

22 changed files with 300 additions and 380 deletions

View File

@ -7,197 +7,151 @@ 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.original_xml.appendChild(head) entry_xml.appendChild(head)
# entry_xml.appendChild(head.cloneNode(True))
status = _original_xml_query_selector("head status", entry, doc) status = doc.createElement("status")
status.textContent = entry.status status.textContent = entry.status
# head.appendChild(status.cloneNode(True)) head.appendChild(status)
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)
# headword.appendChild(headword_lemma.cloneNode(True)) homonymy = doc.createElement("homonymy")
# head.appendChild(headword.cloneNode(True)) headword.appendChild(homonymy)
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")
if hFeature.id >= 0:
feature = original_homonymy[hFeature.id]
else:
homonymy.appendChild(feature)
feature.textContent = hFeature.value 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"]) feature.setAttribute("name", hFeature["name"])
homonymy.appendChild(feature)
# if({}) works uncorrectly in transcrypt # if({}) works uncorrectly in transcrypt
if len(entry.lexical_unit) > 0: 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("id", entry.lexical_unit["id"])
lexunit.setAttribute("type", "single") 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.setAttribute("lexical_unit_lexeme_id", entry.lexical_unit["id"])
lexeme.textContent = entry.lexical_unit["text"] lexeme.textContent = entry.lexical_unit["text"]
# lexunit.appendChild(lexeme.cloneNode(True)) lexunit.appendChild(lexeme)
# head.appendChild(lexunit.cloneNode(True)) head.appendChild(lexunit)
# Example of keeping original xml and adding changes to it only
grammar = _original_xml_query_selector("head grammar", entry, doc) grammar = doc.createElement("grammar")
grammar_category = _original_xml_query_selector("head grammar category", entry, doc) grammar_category = doc.createElement("category")
grammar_category.textContent = entry.grammar 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: if len(entry.measure) > 0:
measure_list = _original_xml_query_selector("head measureList", entry, doc) measure_list = doc.createElement("measureList")
measure = _original_xml_query_selector("head measureList measure", entry, doc) measure = doc.createElement("measure")
# 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"]
# 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: for v in entry.variants:
variant = doc.createElement("variant") variant = doc.createElement("variant")
if v.id >= 0: variant.textContent = v
variant = og_variants[v.id]
else:
variants.appendChild(variant) 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: 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)
relateEntry.textContent = re.value head.appendChild(_export_label_list(doc, entry.labels))
_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.cloneNode(True)) head.appendChild(comment)
# 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.original_xml.appendChild(body) entry_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 definition in sense.definitions: for typ, text in sense.definition.items():
definition_xml = definition.original_xml if definition.original_xml != None else doc.createElement("definition") definition = doc.createElement("definition")
definition_list.appendChild(definition_xml) definition.textContent = text
definition_xml.textContent = definition.value definition.setAttribute("type", typ)
definition_xml.setAttribute("type", definition.type) definition_list.appendChild(definition)
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")
sense_xml.appendChild(translation_container_list)
export_translation_list(doc, sense, translation_container_list) 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") 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_list) example_container = example.export(doc)
translation_container_list = example_container.querySelector("exampleContainer > translationContainerList")
if translation_container_list is None:
translation_container_list = doc.createElement("translationContainerList") translation_container_list = doc.createElement("translationContainerList")
example_container.appendChild(translation_container_list)
export_translation_list(doc, example, translation_container_list) 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): 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, xml_parent) translation_container = export_translation(doc, translation)
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, xml_parent): def export_translation(doc, translation):
translation_xml = translation.original_xml if translation.original_xml != None else doc.createElement("translationContainer") translation_xml = doc.createElement("translationContainer")
xml_parent.appendChild(translation_xml) translation_xml.appendChild(_export_label_list(doc, translation.tags))
_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)
@ -206,43 +160,30 @@ def export_translation(doc, translation, xml_parent):
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 :
_export_explanation_list(doc, translation.explanationList, translation_xml) explanationList = _export_explanation_list(doc, translation.explanationList)
translation_xml.appendChild(explanationList)
return translation_xml return translation_xml
def _export_explanation_list(doc, lst, xml_parent): def _export_explanation_list(doc, lst):
result = xml_parent.querySelector("explanationList") result = doc.createElement('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))
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 return result
def _original_xml_query_selector(selector, entry, doc, parent_selector = selector.rsplit(' ', 1)[0]): def _export_label_list(doc, lst):
query = entry.original_xml.querySelector(selector) result = doc.createElement("labelList")
if query is None: for key, value in lst:
query = doc.createElement(selector.rsplit(' ', 1)[1]) key, value = export_tag(key, value)
entry.original_xml.querySelector(parent_selector).appendChild(query)
return query label_el = doc.createElement("label")
label_el.textContent = value
label_el.setAttribute('type', key)
result.appendChild(label_el)
return result

View File

@ -24,32 +24,33 @@ def build_structure_conversions():
if line[1] == "struktura": if line[1] == "struktura":
continue continue
vto_structure = line[1].strip().split(">")[1].split("<")[0]
vto_name = line[2].strip() vto_name = line[2].strip()
vto_id = line[4].strip() vto_id = line[6].strip()
if 0 in (len(vto_name), len(vto_id)): if 0 in (len(vto_name), len(vto_id)):
continue continue
vfrom = "^" + line[0].replace("?", "\?").replace("%s", "([a-zA-Z螚ȎŠ-]+)") + "$" 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): def convert_structure(structure, type):
if structure_conversions is None: if structure_conversions is None:
build_structure_conversions() 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) match = structure.match(vfrom)
# fix for ids 65, 66, 67 which instead matched with 64 # fix for ids 106, 107, 44 which instead matched with 30
if match and vto_id == '64' and '-s' in type: if match and vto_id == '30' and '-s' in type:
vto_name = 's0-vp-s0' vto_name = 's0-vp-s0'
vto_id = '65' vto_id = '106'
elif match and vto_id == '64' and '-g' in type: elif match and vto_id == '30' and '-g' in type:
vto_name = 'gg-vp-gg' vto_name = 'gg-vp-gg'
vto_id = '66' vto_id = '107'
elif match and vto_id == '64' and '-r' in type: elif match and vto_id == '30' and '-r' in type:
vto_name = 'r-vp-r' vto_name = 'r-vp-r'
vto_id = '67' vto_id = '44'
if match: if match:
# we need to remove replace alias here as we want to use javascript's one # 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() result = structure.replace(vfrom, vto_name).strip()
__pragma__('alias', 'replace', "py_replace") __pragma__('alias', 'replace', "py_replace")
return result, vto_id return result, vto_structure, vto_id
window.console.log("Unknown structure: ", structure) window.console.log("Unknown structure: ", structure)
return 'N/A', '/' return 'N/A', '/'

View File

@ -4,10 +4,8 @@ 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 = {"value": input_el.value} result_candidate = input_el.value
if input_el.hasAttribute("data-id"): if result_candidate != "":
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
@ -15,19 +13,16 @@ 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"):
output = {} firstValue = row.querySelector("." + firstParameter + "-input").value
output[firstParameter] = row.querySelector("." + firstParameter + "-input").value secondValue = row.querySelector("." + secondParameter + "-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 [output[firstParameter], output[secondParameter]]): if (allowEmptyField is False and '' in [firstValue, secondValue]):
continue 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 continue
result.append(output) result.append({firstParameter: firstValue, secondParameter: secondValue})
return result return result
@ -38,7 +33,6 @@ 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
@ -50,7 +44,7 @@ def label_list_getter():
if not value: if not value:
continue continue
result.append((ltype.textContent, value, idx)) result.append((ltype.textContent, value))
kontrastivno = document.getElementById("kontrastivno-input").checked; kontrastivno = document.getElementById("kontrastivno-input").checked;
if kontrastivno: if kontrastivno:

View File

@ -21,9 +21,7 @@ class DeleteRelatedEntries(DeleteVariants):
class DeleteHomonymy(NoReset): class DeleteHomonymy(NoReset):
def update_model(self, model): def update_model(self, model):
for el in document.getElementsByClassName("name-input"): for el in document.getElementsByClassName("list-adder-input"):
el.value = ""
for el in document.getElementsByClassName("value-input"):
el.value = "" el.value = ""

View File

@ -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

View File

@ -18,15 +18,10 @@ 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)
@ -35,10 +30,7 @@ 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]
@ -50,12 +42,6 @@ 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):

View File

@ -17,14 +17,6 @@ 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):
@ -51,14 +43,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.definitions.append({"type": "indicator", "value": "New Sense"}) sense.definition = {"indicator": "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.definitions[0].value = self.new_text sense.definition["indicator"] = self.new_text
class EditComment(QuestionMessage): class EditComment(QuestionMessage):
@ -94,36 +86,23 @@ 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
@ -139,13 +118,3 @@ 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

View File

@ -59,7 +59,8 @@ class SkeCollocation:
def __init__(self, data): def __init__(self, data):
self.word = data.word self.word = data.word
self.frequency = data.count 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} self.other = {"score": data.score, "cm": data.cm}
@ -102,13 +103,28 @@ def match_gf2_examples(data, *args):
xhr.send(to_send) 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): class SkeModal(ClickMessage):
def on_event(self, event): def on_event(self, event):
# event could be data if this is the return from external library # event could be data if this is the return from external library
if type(event) in [list, int]: if type(event) in [list, int]:
self.add_arg(event) self.add_arg(event)
else: else:
if len(self._args) < 4: if len(self._args) < 5:
self.add_arg(None) self.add_arg(None)
super().on_event(event) super().on_event(event)
@ -116,18 +132,20 @@ class SkeModal(ClickMessage):
page_num = self.get_arg(0, int) page_num = self.get_arg(0, int)
search_term = self.get_arg(1, str) search_term = self.get_arg(1, str)
ske_index = self.get_arg(2, int) 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) 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 # could be none if empty
data = self.get_arg(3) data = self.get_arg(4)
if data is None: if data is None:
params = {"additional_refs": "s.id,p.id", params = {"additional_refs": "s.id,p.id",
"page_num": page_num, "page_num": page_num,
"error_callback": next_message, "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") gdex = get_preference("ske_gdex")
if gdex: if gdex:
@ -136,15 +154,36 @@ class SkeModal(ClickMessage):
return return
params["gdex"] = gdex 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) model.ske.request(search_term, next_message, ske_lookup, params)
search_term = search_term_old
elif type(data) is list: elif type(data) is list:
window.console.log(data) window.console.log(data)
# check if gf2 examples are loaded or not # check if gf2 examples are loaded or not
if not data[0].gf2_check and type(data[0]) is SkeExample: 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 # 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( model.modal_set(lambda: modals.ske_list(
search_term, data, page_num, model.entry.senses, model.ske.request_kinds)) search_term, data, page_num, model.entry.senses, model.ske.request_kinds))
@ -155,7 +194,7 @@ class SkeModal(ClickMessage):
class SkeModalGf2Update(SkeModal): class SkeModalGf2Update(SkeModal):
def on_event(self, event): def on_event(self, event):
response_data = window.JSON.parse(event.target.response) response_data = window.JSON.parse(event.target.response)
data = self.get_arg(3) data = self.get_arg(4)
data_dict = {} data_dict = {}
for example in data: for example in data:
@ -191,6 +230,7 @@ class SearchInSkeModal(SkeModal):
self.add_arg(int(document.getElementById("ske-page-num").value)) self.add_arg(int(document.getElementById("ske-page-num").value))
self.add_arg(document.getElementById("ske-search").value) self.add_arg(document.getElementById("ske-search").value)
self.add_arg(document.getElementById("ske-select").selectedIndex) self.add_arg(document.getElementById("ske-select").selectedIndex)
self.add_arg(document.getElementById("ske-pos-query").value)
super().on_event(event) super().on_event(event)
@ -238,7 +278,7 @@ class SkeInsert(DataChgClickMessage):
lex_mid = ComponentLexeme() lex_mid = ComponentLexeme()
lex_mid.text = example["mid"] lex_mid.text = example["mid"]
lex_mid.role = "collocation" lex_mid.role = "headword"
lex_right = ComponentLexeme() lex_right = ComponentLexeme()
lex_right.text = example["right"] lex_right.text = example["right"]
@ -257,17 +297,45 @@ class SkeInsert(DataChgClickMessage):
new_collocation.inner.other_attributes["frequency"] = example.frequency new_collocation.inner.other_attributes["frequency"] = example.frequency
new_collocation.inner.type = "collocation" new_collocation.inner.type = "collocation"
lex_left = ComponentLexeme() headword = document.getElementById("ske-search").value
lex_left.text = "" lexemes = []
lex_left.role = None 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
lex_mid = ComponentLexeme() for i in range(len(structure_name)):
lex_mid.text = example.word lex = ComponentLexeme()
lex_mid.role = "collocation" structure[i] = structure[i].replace("Inf-", "")
lex_right = ComponentLexeme() # take care of negations "ne"
lex_right.text = "" if "Neg-" in structure[i]:
lex_right.role = None structure[i] = structure[i].replace("Neg-", "")
negation_flag = True
n_lex = ComponentLexeme()
n_lex.text = "ne"
n_lex.role = "other"
lexemes.append(n_lex)
new_collocation.components.extend([lex_left, lex_mid, lex_right]) 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 return new_collocation

View File

@ -14,7 +14,6 @@ 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 = []
@ -22,19 +21,10 @@ 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)

View File

@ -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).items(): for key, value in dict(self._copy).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

View File

@ -26,8 +26,7 @@ class Entry(Data):
self.original_xml = None self.original_xml = None
def import_xml(self, entry_xml): def import_xml(self, entry_xml):
console.log(entry_xml) self.original_xml = entry_xml.cloneNode(True)
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")
@ -40,9 +39,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 = [{"value": v.textContent, "id": index} for index, v in enumerate(entry_xml.querySelectorAll("head variantList variant"))] self.variants = [v.textContent for v in 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.homonymy = [{"value": v.textContent, "name": v.getAttribute("name")} for v in 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.related_entries = [re.textContent for re in 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:
@ -55,13 +54,12 @@ 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", 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")): 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):
@ -98,7 +96,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(v.value for v in self.variants))) view_table.append((buttons[0], ", ".join(self.variants)))
if len(self.homonymy) == 0: if len(self.homonymy) == 0:
view_buttons.append(buttons[4]) view_buttons.append(buttons[4])
@ -108,7 +106,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(re.value for re in self.related_entries))) view_table.append((buttons[1], ", ".join(self.related_entries)))
if len(self.labels) == 0: if len(self.labels) == 0:
view_buttons.append(buttons[2]) view_buttons.append(buttons[2])
@ -143,3 +141,4 @@ class Entry(Data):
if translation in cluster: if translation in cluster:
cluster.remove(translation) cluster.remove(translation)
return return

View File

@ -11,10 +11,8 @@ 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
@ -27,7 +25,6 @@ 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
@ -35,8 +32,7 @@ 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 = self.original_xml if self.original_xml is not None else doc.createElement("comp") result = doc.createElement("comp")
result.setAttribute("role", self.role) result.setAttribute("role", self.role)
result.textContent = self.text result.textContent = self.text

View File

@ -3,17 +3,14 @@ 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 = self.original_xml if self.original_xml is not None else doc.createElement("corpusExample") result = doc.createElement("corpusExample")
if modified: if modified:
result.setAttribute("modified", "true") result.setAttribute("modified", "true")

View File

@ -13,7 +13,6 @@ 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 = []
@ -42,20 +41,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 = self.original_xml.querySelector("corpusExample") inner_xml = example_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 = self.original_xml.querySelector("multiwordExample") inner_xml = example_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(self.inner.original_xml.childNodes): for idx, comp_xml in enumerate(inner_xml.childNodes):
comp = ComponentLexeme() comp = ComponentLexeme()
comp.import_xml(comp_xml) comp.import_xml(comp_xml)
if comp.isValid(): if comp.isValid():
@ -63,10 +62,11 @@ class Example(Data):
self.check_multiword_components() self.check_multiword_components()
def export(self, doc, xml_parent): def export(self, doc):
self.check_multiword_components() 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) 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:

View File

@ -6,10 +6,8 @@ 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)
@ -19,9 +17,6 @@ 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"):
@ -32,8 +27,8 @@ class MultiwordExample:
return cluster return cluster
def export(self, doc, _modified): 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(): for key, value in self.other_attributes.items():
result.setAttribute(key, value) result.setAttribute(key, value)

View File

@ -7,15 +7,14 @@ 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_xml): def import_dom(self, explanation_dom):
self.original_xml = explanation_xml.cloneNode(True)
self.value = explanation_xml.textContent if explanation_xml else "" self.value = explanation_dom.textContent if explanation_dom else ""
self.language = explanation_xml.getAttribute("language") if explanation_xml.hasAttribute("language") else "" self.language = explanation_dom.getAttribute("language") if explanation_dom.hasAttribute("language") else ""
def export(self, doc): 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 result.textContent = self.value
if self.language != "": result.setAttribute('language', self.language) if self.language != "": result.setAttribute('language', self.language)

View File

@ -11,34 +11,25 @@ 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.original_xml = None self.definition = {}
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 self.original_xml.querySelectorAll("definitionList definition"): for definition in sense_xml.querySelectorAll("definitionList definition"):
definition_object = {} key = definition.getAttribute("type")
definition_object.type = definition.getAttribute("type") self.definition[key] = definition.textContent
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", self.original_xml) self.labels = import_label_list("sense > labelList label", sense_xml)
self.translations = from_container_list( self.translations = from_container_list(
self.original_xml.querySelectorAll('sense > translationContainerList translationContainer')) sense_xml.querySelectorAll('sense > translationContainerList translationContainer'))
for example_xml in self.original_xml.querySelectorAll("exampleContainerList exampleContainer"): for example_xml in sense_xml.querySelectorAll("exampleContainerList exampleContainer"):
example = Example() example = Example()
example.import_xml(example_xml) example.import_xml(example_xml)
self.examples.append(example) self.examples.append(example)
example_xml.remove()
console.log(self.original_xml)
def merge_labels(self): def merge_labels(self):
@ -53,7 +44,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) }}, ", ".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", {}, View.view_translations(self.translations, self, model)),
h("div", {}, examples)])]) h("div", {}, examples)])])
return result return result

View File

@ -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 index, tag_xml in enumerate(xml_element.querySelectorAll(selector)): for tag_xml in 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, index)) result.append((t_type, t_value))
return result return result

View File

@ -20,8 +20,6 @@ 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:
@ -32,7 +30,6 @@ 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 = ""
@ -42,7 +39,6 @@ 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
@ -50,13 +46,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 = self.original_xml.querySelectorAll("explanationList explanation") explanationList = translation_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", self.original_xml) self.tags = import_label_list("labelList label", translation_xml)
def view(self, model): def view(self, model):
elements = [] elements = []

View File

@ -42,19 +42,15 @@ 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.value or slabel}, "attrs": idAttr}, "")])) h("input.list-adder-input", {"props": {"type": "text", "value": slabel}}, "")]))
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, labelId): def split_line2(left, right):
cls = "flex.two{}".format(".double-list-row") cls = "flex.two{}".format(".double-list-row")
isId = {"attrs": {"data-id": labelId}} if labelId >= 0 else {} return h("div.{}".format(cls), {}, [
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)]
@ -62,20 +58,19 @@ 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, "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("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, feature.id)) content.append(split_line2(name, value))
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, labelId): def split_line2(left, right):
cls = "flex.two{}".format(".double-list-row") cls = "flex.two{}".format(".double-list-row")
isId = {"attrs": {"data-id": labelId}} if labelId >= 0 else {} return h("div.{}".format(cls), {}, [
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)]
@ -87,7 +82,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, explanation.id)) content.append(split_line2(value, language))
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
@ -95,13 +90,12 @@ 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, labelId, is_llr=True): def split_line3(left, center, right, 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), isId, [ return h("div.{}".format(cls), {}, [
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, index): def dropdown_right(label_type, label):
left = h("span.label-type", {}, label_type) left = h("span.label-type", {}, label_type)
options = [h("option", {}, [])] 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"}}, {"props": {"type": "text", "value": right_value, "placeholder": "drugo"}},
[]) [])
return split_line3(left, center, right, index) return split_line3(left, center, right)
content = [] content = []
kontrastivno = False kontrastivno = False
for key, value, idx in current_labels: for key, value 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():

View File

@ -40,9 +40,7 @@ def edit_sense_label(sense):
def edit_example(example, sense): def edit_example(example, sense):
example_original = example example_original = example
# example = example_original.deepcopy() example = example_original.copy()
# 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)
@ -66,6 +64,7 @@ def edit_example(example, sense):
result.append(h("span.example-component-button.example-component-none", result.append(h("span.example-component-button.example-component-none",
{"on": {"click": role_msg(idx, "none")}}, "N")) {"on": {"click": role_msg(idx, "none")}}, "N"))
if "-" not in example.inner.other_attributes["structureName"]:
result.extend([ result.extend([
h("span.example-component-button", h("span.example-component-button",
{"on": {"click": message.msg(message.ExampleComponentAdd, example_original, idx)}}, "+"), {"on": {"click": message.msg(message.ExampleComponentAdd, example_original, idx)}}, "+"),
@ -74,6 +73,9 @@ def edit_example(example, sense):
return result 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): for idx, component in enumerate(example.components):
role_txt = component.role if component.role is not None else "none" role_txt = component.role if component.role is not None else "none"
color_class = ".example-component-" + role_txt color_class = ".example-component-" + role_txt
@ -102,7 +104,6 @@ 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,))
@ -119,7 +120,7 @@ def edit_entry_labels(entry):
def edit_sense_definition(sense): 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): def edit_comment(comment):
@ -138,7 +139,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.definitions[0].value) text = "{}: {}".format(idx + 1, sense.definition["indicator"])
id_ = "choose-example-{}".format(idx) id_ = "choose-example-{}".format(idx)
props = {"type": "radio", "name": "choose-example"} props = {"type": "radio", "name": "choose-example"}
@ -180,6 +181,10 @@ def ske_list(search_term, data, page_num, senses, ske_kinds):
"type": "number", "type": "number",
"min": 1, "min": 1,
"step": 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", h("span.fourth.button.ske-right-button",
{"on": {"click": message.msg(message.SearchInSkeModal)}}, "Isci")]), {"on": {"click": message.msg(message.SearchInSkeModal)}}, "Isci")]),
h("div.ske-list", h("div.ske-list",
@ -188,6 +193,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.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)) return modal_template(contents, "SKE", (message.SkeInsert, data))

View File

@ -58,7 +58,7 @@ class View:
def view_ske_button(model): def view_ske_button(model):
return h( return h(
"span#ske-button.button.toggle", "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", { h("svg#ske-img", {
"attrs": { "attrs": {
"xmlns": "http://www.w3.org/2000/svg", "xmlns": "http://www.w3.org/2000/svg",