From eea25b996854ce636f3b080fe540730eaf1e7330 Mon Sep 17 00:00:00 2001 From: matic_t Date: Tue, 29 Sep 2020 04:07:05 -0700 Subject: [PATCH 1/6] export multiword example as new entry --- src/export.py | 134 ++++++++++++++++++++++++++++++++++++ src/message/__init__.py | 2 +- src/message/example_edit.py | 17 ++++- src/model/sense.py | 1 - src/view/view.py | 9 ++- 5 files changed, 158 insertions(+), 5 deletions(-) diff --git a/src/export.py b/src/export.py index 94792f2..7ffdafc 100644 --- a/src/export.py +++ b/src/export.py @@ -190,3 +190,137 @@ def _export_label_list(doc, lst): label_el.setAttribute('type', key) result.appendChild(label_el) 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_example_to_entry_xml(example): + parser = __new__(DOMParser()) + doc = parser.parseFromString("", "text/xml") + entry_xml = doc.firstChild + + head = doc.createElement("head") + entry_xml.appendChild(head) + + status = doc.createElement("status") + head.appendChild(status) + + headword = doc.createElement("headword") + head.appendChild(headword) + + lemma = doc.createElement("lemma") + lemma.textContent = " ".join(comp.text for comp in example.components) + lemma.setAttribute("type", "compound") + headword.appendChild(lemma) + + homonymy = doc.createElement("homonymy") + headword.appendChild(homonymy) + + lexical_unit = doc.createElement("lexicalUnit") + lexical_unit.setAttribute("type", "MWE") + head.appendChild(lexical_unit) + + if example.inner.other_attributes['structure_id'] != None: + lexical_unit.setAttribute("structure_id", example.inner.other_attributes['structure_id']) + + for comp in example.components: + comp_xml = doc.createElement("component") + lexeme = doc.createElement("lexeme") + lexeme.textContent = comp.text + comp_xml.appendChild(lexeme) + lexical_unit.appendChild(comp_xml) + + grammar = doc.createElement("grammar") + category = doc.createElement("category") + grammar.appendChild(category) + head.appendChild(grammar) + + variant_list = doc.createElement("variantList") + head.appendChild(variant_list) + related_entry_list = doc.createElement("relatedEntryList") + head.appendChild(related_entry_list) + label_list = doc.createElement("labelList") + head.appendChild(label_list) + comment = doc.createElement("comment") + head.appendChild(comment) + + body = doc.createElement("body") + entry_xml.appendChild(body) + + sense_list = doc.createElement("senseList") + body.appendChild(sense_list) + + sense = doc.createElement("sense") + sense_list.appendChild(sense) + + sense_label_list = doc.createElement("labelList") + sense.appendChild(sense_label_list) + + first_translation = example.translations[0][0] + translation_label_list = doc.createElement("labelList") + + # Add labels to sense if label value isn't kontrastivno or približek else keep them in translation + for key, value in first_translation.tags: + key, value = export_tag(key, value) + label_el = doc.createElement("label") + label_list = translation_label_list if value == "kontrastivno" or value == "približek" else sense_label_list + # if idx >= 0: + # label_el = first_translation.original_xml.querySelectorAll("labelList label")[idx].cloneNode(True) + + label_el.textContent = value + label_el.setAttribute('type', key) + + label_list.appendChild(label_el) + + # Set definition as explanation if explanation in slo + definition_list = doc.createElement("definitionList") + sense.appendChild(definition_list) + for explanation in first_translation.explanationList: + if explanation.language == "slo": + definition = doc.createElement("definition") + definition.setAttribute("type", "indicator") + definition.textContent = explanation.value + definition_list.appendChild(definition) + first_translation.explanationList.remove(explanation) + + translation_container_list = doc.createElement("translationContainerList") + sense.appendChild(translation_container_list) + + translation_container = doc.createElement("translationContainer") + translation_container_list.appendChild(translation_container) + + if len(translation_label_list) > 0: + translation_container.appendChild(translation_label_list) + + # translation = first_translation.original_xml.querySelector("translation").cloneNode(True) if first_translation.original_xml != None else doc.createElement("translation") + translation = doc.createElement("translation") + translation_container.appendChild(translation) + + translation.textContent = first_translation.translation + translation.setAttribute("targetLang", first_translation.targetLang) + + if first_translation.audio: + translation.setAttribute("audio", first_translation.audio) + + if first_translation.source: + translation.setAttribute("source", first_translation.source) + + if len(first_translation.explanationList) > 0 : + _export_explanation_list(doc, first_translation.explanationList, translation) + + + example.translations[0] = example.translations[0][1:] + export_translation_list(doc, example, translation_container_list) + + return doc + # for comp in example.components: + # if comp.role == "collocate": + # self.headword = comp.role + # break + + # self.headword = example. \ No newline at end of file diff --git a/src/message/__init__.py b/src/message/__init__.py index 0e18322..81bafe6 100644 --- a/src/message/__init__.py +++ b/src/message/__init__.py @@ -4,7 +4,7 @@ from message.show_messages import ShowEntryLabelsEdit, ShowEditTranslation, Show from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, AddExampleTranslation, DoChosenExamples, AddToLabelList, AddToGenericList, EditVariants, EditHomonymy, EditRelatedEntries, EditEntryLabels, ExampleClusterEdit, ExampleClusterAdd from message.show_menu import ShowTranslationMenu, ShowSenseMenu, ShowExampleMenu from message.sense_edit import SenseMoveUp, SenseMoveDown, SenseBin, AddMultiwordExample -from message.example_edit import ExampleMoveUp, ExampleMoveDown, ExampleBin, ExampleRoleChange, ExampleComponentSpace, ExampleComponentAdd, ExampleComponentRemove, EditExampleText, ToggleExamples, ToggleClusters +from message.example_edit import ExampleAsNewEntry, ExampleMoveUp, ExampleMoveDown, ExampleBin, ExampleRoleChange, ExampleComponentSpace, ExampleComponentAdd, ExampleComponentRemove, EditExampleText, ToggleExamples, ToggleClusters from message.delete_messages import DeleteComment, DeleteVariants, DeleteHomonymy, DeleteRelatedEntries, DeleteEntryLabels from message.ske_messages import ShowSkeModal, SearchInSkeModal, SkeInsert diff --git a/src/message/example_edit.py b/src/message/example_edit.py index 7b06fc0..03bee6c 100644 --- a/src/message/example_edit.py +++ b/src/message/example_edit.py @@ -3,6 +3,10 @@ from message.simple_messages import DataChgClickMessage, ClickMessage, NoReset from message.message import Message from model.example import Example, ComponentLexeme from model.sense import Sense +from model.entry import Entry +from model.model import Model +import lib.screenful as screenful +from export import export_to_xml, export_example_to_entry_xml @@ -13,6 +17,17 @@ def _get_example_idx(example, model): return (sense, eidx) +class ExampleAsNewEntry(ClickMessage): + def update_model(self, model): + example = self.get_arg(0, Example) + entry_xml = export_example_to_entry_xml(example) + new_entry = Entry() + new_entry.import_xml(entry_xml) + + new_model = Model() + new_model.entry = new_entry + screenful.screenful().Editor['new'](None, export_to_xml(new_model)) + class ExampleMoveUp(DataChgClickMessage): def update_model(self, model): example = self.get_arg(0, Example) @@ -60,7 +75,7 @@ class EditExampleText(Message): if example.newly_created: example.newly_created = False sense.examples.append(example) - + idx = 0 for txt in document.getElementsByClassName("example-component-text"): example.components[idx].text = txt.value diff --git a/src/model/sense.py b/src/model/sense.py index 4e9e6cc..2566c7f 100644 --- a/src/model/sense.py +++ b/src/model/sense.py @@ -37,7 +37,6 @@ class Sense(Data): def merge_labels(self): return ", ".join(val for _, val in self.labels) - def view(self, model, sense_num): examples = [example.view(model, self) for example in self.examples] diff --git a/src/view/view.py b/src/view/view.py index de61a85..083901a 100644 --- a/src/view/view.py +++ b/src/view/view.py @@ -98,11 +98,16 @@ class View: elif type(menu_target) is Example: example = menu_target sense = example_sense(example, entry) - return h("span.popup-menu", { "style": style }, [ + dom_children = [ h("button.shyButton", { "on": {"click": msg(ShowExampleEdit, example, sense)}}, "✎"), h("button.shyButton", { "on": {"click": msg(ExampleMoveUp, example)}}, "↑"), h("button.shyButton", { "on": {"click": msg(ExampleMoveDown, example)}}, "↓"), - h("button.shyButton", { "on": {"click": msg(ExampleBin, example)}}, "🗑")]) + h("button.shyButton", { "on": {"click": msg(ExampleBin, example)}}, "🗑")] + + if example.is_multiword(): + dom_children.insert(1, h("button.shyButton", { "on": {"click": msg(ExampleAsNewEntry, example, sense)}}, "As new Entry")) + + return h("span.popup-menu", { "style": style }, dom_children) else: console.log("Should not be heree!!") From bd4e64f818821c12b95efd5a9673b0c101e368e5 Mon Sep 17 00:00:00 2001 From: matic_t Date: Tue, 29 Sep 2020 04:07:28 -0700 Subject: [PATCH 2/6] lexicalUnit from single lexeme to multiple lexeme support --- src/export.py | 16 +++++++++------- src/model/entry.py | 17 ++++++++++++----- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/export.py b/src/export.py index 7ffdafc..b296e23 100644 --- a/src/export.py +++ b/src/export.py @@ -46,15 +46,17 @@ def export_entry(entry): # if({}) works uncorrectly in transcrypt - if len(entry.lexical_unit) > 0: + if len(entry.lexical_unit) > 0 and len(entry.lexical_unit['lexemes']) > 0: lexunit = doc.createElement("lexicalUnit") lexunit.setAttribute("id", entry.lexical_unit["id"]) - lexunit.setAttribute("type", "single") - lexeme = doc.createElement("lexeme") - lexeme.setAttribute("lexical_unit_lexeme_id", entry.lexical_unit["id"]) - lexeme.textContent = entry.lexical_unit["text"] - - lexunit.appendChild(lexeme) + lexunit.setAttribute("type", entry.lexical_unit['type']) + for lexeme in entry.lexical_unit["lexemes"]: + component = doc.createElement('component') + lexeme_xml = doc.createElement("lexeme") + component.appendChild(lexeme_xml) + lexeme_xml.setAttribute("lexical_unit_lexeme_id", lexeme["id"]) + lexeme_xml.textContent = lexeme["text"] + lexunit.appendChild(component) head.appendChild(lexunit) diff --git a/src/model/entry.py b/src/model/entry.py index 5e60489..c3c6fa9 100644 --- a/src/model/entry.py +++ b/src/model/entry.py @@ -42,11 +42,18 @@ class Entry(Data): 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: - self.lexical_unit['id'] = lex_unit.getAttribute("lexical_unit_lexeme_id") - self.lexical_unit['text'] = lex_unit.textContent + lex_units = entry_xml.querySelectorAll("lexical_unit lexeme,lexicalUnit lexeme") + lex_unit_parent = entry_xml.querySelector("lexicalUnit") + self.lexical_unit['lexemes'] = [] + self.lexical_unit['id'] = lex_unit_parent.getAttribute('id') if lex_unit_parent and lex_unit_parent.hasAttribute( + "id") else None + self.lexical_unit['type'] = lex_unit_parent.getAttribute("type") if lex_unit_parent and lex_unit_parent.hasAttribute( + "type") else "single" + for unit in lex_units: + lexical_unit = {} + lexical_unit['id'] = unit.getAttribute("lexical_unit_lexeme_id") + lexical_unit['text'] = unit.textContent + self.lexical_unit['lexemes'].append(lexical_unit) measure = entry_xml.querySelector("measureList measure") if measure: From 5e741343c308a37b1b29ec23c93240cf937480af Mon Sep 17 00:00:00 2001 From: matic_t Date: Mon, 5 Oct 2020 03:41:07 -0700 Subject: [PATCH 3/6] finished --- src/export.py | 57 ++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/src/export.py b/src/export.py index b296e23..ea70b3f 100644 --- a/src/export.py +++ b/src/export.py @@ -1,6 +1,6 @@ from browser import document from model.tags import export_tag - +from model.translation import Translation def export_to_xml(model): xml_document = export_entry(model.entry) @@ -146,10 +146,11 @@ def export_sense(doc, sense): 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) - translation_container.setAttribute("cluster", str(cidx + 1)) - xml_parent.appendChild(translation_container) + if len(cluster) > 0: + for translation in cluster: + translation_container = export_translation(doc, translation) + translation_container.setAttribute("cluster", str(cidx + 1)) + xml_parent.appendChild(translation_container) def export_translation(doc, translation): @@ -200,7 +201,6 @@ def _original_xml_query_selector(selector, entry, doc, parent_selector = selecto entry.original_xml.querySelector(parent_selector).appendChild(query) return query - def export_example_to_entry_xml(example): parser = __new__(DOMParser()) doc = parser.parseFromString("", "text/xml") @@ -227,8 +227,8 @@ def export_example_to_entry_xml(example): lexical_unit.setAttribute("type", "MWE") head.appendChild(lexical_unit) - if example.inner.other_attributes['structure_id'] != None: - lexical_unit.setAttribute("structure_id", example.inner.other_attributes['structure_id']) + if example.inner.other_attributes['structure_id'] != None and len(example.components) <= 3: + lexical_unit.setAttribute("id", example.inner.other_attributes['structure_id']) for comp in example.components: comp_xml = doc.createElement("component") @@ -263,7 +263,8 @@ def export_example_to_entry_xml(example): sense_label_list = doc.createElement("labelList") sense.appendChild(sense_label_list) - first_translation = example.translations[0][0] + first_translation = example.translations[0][0] if len(example.translations) > 0 and len(example.translations[0]) > 0 else Translation() + first_translation_is_valid = False translation_label_list = doc.createElement("labelList") # Add labels to sense if label value isn't kontrastivno or približek else keep them in translation @@ -271,8 +272,6 @@ def export_example_to_entry_xml(example): key, value = export_tag(key, value) label_el = doc.createElement("label") label_list = translation_label_list if value == "kontrastivno" or value == "približek" else sense_label_list - # if idx >= 0: - # label_el = first_translation.original_xml.querySelectorAll("labelList label")[idx].cloneNode(True) label_el.textContent = value label_el.setAttribute('type', key) @@ -294,35 +293,33 @@ def export_example_to_entry_xml(example): sense.appendChild(translation_container_list) translation_container = doc.createElement("translationContainer") - translation_container_list.appendChild(translation_container) if len(translation_label_list) > 0: translation_container.appendChild(translation_label_list) - # translation = first_translation.original_xml.querySelector("translation").cloneNode(True) if first_translation.original_xml != None else doc.createElement("translation") - translation = doc.createElement("translation") - translation_container.appendChild(translation) + if first_translation.translation is not "": + translation = doc.createElement("translation") + translation_container.appendChild(translation) - translation.textContent = first_translation.translation - translation.setAttribute("targetLang", first_translation.targetLang) + translation.textContent = first_translation.translation + translation.setAttribute("targetLang", first_translation.targetLang) - if first_translation.audio: - translation.setAttribute("audio", first_translation.audio) + if first_translation.audio: + translation.setAttribute("audio", first_translation.audio) - if first_translation.source: - translation.setAttribute("source", first_translation.source) + if first_translation.source: + translation.setAttribute("source", first_translation.source) + first_translation_is_valid = True if len(first_translation.explanationList) > 0 : - _export_explanation_list(doc, first_translation.explanationList, translation) + explanation_list = _export_explanation_list(doc, first_translation.explanationList) + translation_container.appendChild(explanation_list) + first_translation_is_valid = True + if first_translation_is_valid: + translation_container_list.appendChild(translation_container) - example.translations[0] = example.translations[0][1:] + example.translations[0] = example.translations[0][1:] if len(example.translations) > 0 and len(example.translations[0]) > 0 else example.translations[0] export_translation_list(doc, example, translation_container_list) - return doc - # for comp in example.components: - # if comp.role == "collocate": - # self.headword = comp.role - # break - - # self.headword = example. \ No newline at end of file + return doc \ No newline at end of file From 5f26dd603481bf2ca460741e121623e2eec21891 Mon Sep 17 00:00:00 2001 From: matic_t Date: Mon, 5 Oct 2020 06:54:01 -0700 Subject: [PATCH 4/6] Should be finished v2 --- src/export.py | 12 +++++++++++- src/message/__init__.py | 2 +- src/message/show_menu.py | 16 ++++++++++++--- src/message/simple_edits.py | 2 +- src/view/modals.py | 39 +++++++++++++++++++++++++++++++++++-- src/view/view.py | 2 +- 6 files changed, 64 insertions(+), 9 deletions(-) diff --git a/src/export.py b/src/export.py index ea70b3f..8308e98 100644 --- a/src/export.py +++ b/src/export.py @@ -201,7 +201,7 @@ def _original_xml_query_selector(selector, entry, doc, parent_selector = selecto entry.original_xml.querySelector(parent_selector).appendChild(query) return query -def export_example_to_entry_xml(example): +def export_example_to_entry_xml(example, other_examples = None): parser = __new__(DOMParser()) doc = parser.parseFromString("", "text/xml") entry_xml = doc.firstChild @@ -321,5 +321,15 @@ def export_example_to_entry_xml(example): example.translations[0] = example.translations[0][1:] if len(example.translations) > 0 and len(example.translations[0]) > 0 else example.translations[0] export_translation_list(doc, example, translation_container_list) + if other_examples is not None: + example_container_list = doc.createElement("exampleContainerList") + sense.appendChild(example_container_list) + + for example in other_examples: + 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 doc \ No newline at end of file diff --git a/src/message/__init__.py b/src/message/__init__.py index 81bafe6..805bc1a 100644 --- a/src/message/__init__.py +++ b/src/message/__init__.py @@ -1,7 +1,7 @@ from message.simple_messages import NoReset, Reset, ModalNotOkClose, ClickMessage, DataChgClickMessage, KeyboardPress, NoAction from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation from message.show_messages import ShowEntryLabelsEdit, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowExampleEdit, ShowVariantsEdit, ShowHomonymyEdit, ShowRelatedEntriesEdit -from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, AddExampleTranslation, DoChosenExamples, AddToLabelList, AddToGenericList, EditVariants, EditHomonymy, EditRelatedEntries, EditEntryLabels, ExampleClusterEdit, ExampleClusterAdd +from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, AddExampleTranslation, MoveExamplesToSense, AddToLabelList, AddToGenericList, EditVariants, EditHomonymy, EditRelatedEntries, EditEntryLabels, ExampleClusterEdit, ExampleClusterAdd from message.show_menu import ShowTranslationMenu, ShowSenseMenu, ShowExampleMenu from message.sense_edit import SenseMoveUp, SenseMoveDown, SenseBin, AddMultiwordExample from message.example_edit import ExampleAsNewEntry, ExampleMoveUp, ExampleMoveDown, ExampleBin, ExampleRoleChange, ExampleComponentSpace, ExampleComponentAdd, ExampleComponentRemove, EditExampleText, ToggleExamples, ToggleClusters diff --git a/src/message/show_menu.py b/src/message/show_menu.py index a80d0b9..1038dc3 100644 --- a/src/message/show_menu.py +++ b/src/message/show_menu.py @@ -57,11 +57,21 @@ class ShowSenseMenu(ShowMenu): class ShowExampleMenu(KeyPlusClickMessage): def update_model_default(self, model): example = self.get_arg(0, Example) - - # if some are chosen, then show modal for choosing senses + + # if some are chosen, then show modal for choosing actions if len(model.chosen_examples) > 0 and example in model.chosen_examples: chosen_examples = model.chosen_examples - model.modal_set(lambda: modals.do_chosen_examples(chosen_examples, model.entry)) + multiword_example = False + + for chosen_example in chosen_examples: + if chosen_example.is_multiword(): + if multiword_example is False: + multiword_example = chosen_example + else: + multiword_example = False + break + + model.modal_set(lambda: modals.do_chosen_examples(chosen_examples, model, multiword_example)) else: model.menu_location = self.menu_location model.menu_target = example diff --git a/src/message/simple_edits.py b/src/message/simple_edits.py index 927c819..6c4a9cc 100644 --- a/src/message/simple_edits.py +++ b/src/message/simple_edits.py @@ -58,7 +58,7 @@ class EditComment(QuestionMessage): model.entry.comment = self.new_text -class DoChosenExamples(Message): +class MoveExamplesToSense(Message): def update_model(self, model): chosen_examples = self.get_arg(0, list) diff --git a/src/view/modals.py b/src/view/modals.py index b8cccc6..e3c9850 100644 --- a/src/view/modals.py +++ b/src/view/modals.py @@ -2,6 +2,11 @@ from lib.snabbdom import h import message from view.modal_templates import * from view.utils import show_toggle_cluster_buttons +from export import export_to_xml, export_example_to_entry_xml +from update import update +from model.entry import Entry +import lib.screenful as screenful +from model.model import Model import model @@ -127,7 +132,37 @@ def edit_comment(comment): return modal_template(big_question("Edit comment", comment), "Comment", (message.EditComment,), (message.DeleteComment,)) -def do_chosen_examples(example_list, entry): +def do_chosen_examples(example_list, model, multiword_example): + if multiword_example is False: + return move_examples_to_sense(example_list, model.entry) + else: + return modal_template([ + h("button.shyButton", {"on": {"click": (lambda: move_to_view(example_list, model))}}, "Premakni v pomen"), + h("button.shyButton", {"on": {"click": (lambda: export_to_new_entry())}}, + "Izvozi v novo geslo")], "Izberite željeno akcijo", None) + + +def move_to_view(example_list, model): + model.modal_reset() + model.modal_set(lambda: move_examples_to_sense(example_list, model.entry)) + update.view.view(model, True) + + +def export_to_new_entry(multiword_example, example_list): + other_examples = [] + for example in example_list: + if example.is_multiword() is False: + other_examples.append(example) + entry_xml = export_example_to_entry_xml(multiword_example, other_examples if len(example_list) > 0 else None) + new_entry = Entry() + new_entry.import_xml(entry_xml) + + new_model = Model() + new_model.entry = new_entry + screenful.screenful().Editor['new'](None, export_to_xml(new_model)) + + +def move_examples_to_sense(example_list, entry): example_senses = [] for idx, sense in enumerate(entry.senses): for ex in sense.examples: @@ -150,7 +185,7 @@ def do_chosen_examples(example_list, entry): options.append(h("label.checkable", {"attrs": {"for": id_}}, text)) options.append(h("br", {}, [])) - return modal_template(options, "Examples picker", (message.DoChosenExamples, example_list)) + return modal_template(options, "Examples picker", (message.MoveExamplesToSense, example_list)) def ske_list(search_term, data, page_num, senses, ske_kinds): diff --git a/src/view/view.py b/src/view/view.py index 083901a..7ebbb4a 100644 --- a/src/view/view.py +++ b/src/view/view.py @@ -105,7 +105,7 @@ class View: h("button.shyButton", { "on": {"click": msg(ExampleBin, example)}}, "🗑")] if example.is_multiword(): - dom_children.insert(1, h("button.shyButton", { "on": {"click": msg(ExampleAsNewEntry, example, sense)}}, "As new Entry")) + dom_children.insert(1, h("button.shyButton", { "on": {"click": msg(ExampleAsNewEntry, example, sense)}}, "Izvozi v novo geslo")) return h("span.popup-menu", { "style": style }, dom_children) else: From fe3b3dfb0c3ecbea09aa88c8fee6a0ea6de141cf Mon Sep 17 00:00:00 2001 From: matic_t Date: Mon, 5 Oct 2020 08:18:53 -0700 Subject: [PATCH 5/6] Should be finished v3 --- src/view/modals.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/view/modals.py b/src/view/modals.py index e3c9850..48e8c3d 100644 --- a/src/view/modals.py +++ b/src/view/modals.py @@ -138,7 +138,7 @@ def do_chosen_examples(example_list, model, multiword_example): else: return modal_template([ h("button.shyButton", {"on": {"click": (lambda: move_to_view(example_list, model))}}, "Premakni v pomen"), - h("button.shyButton", {"on": {"click": (lambda: export_to_new_entry())}}, + h("button.shyButton", {"on": {"click": (lambda: export_to_new_entry(multiword_example, example_list))}}, "Izvozi v novo geslo")], "Izberite željeno akcijo", None) From bc897dbe060eef440ffacb7cc6f492c133776ac5 Mon Sep 17 00:00:00 2001 From: matic_t Date: Wed, 7 Oct 2020 04:40:46 -0700 Subject: [PATCH 6/6] Should be finished v4 --- src/export.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/export.py b/src/export.py index 8308e98..f0ffba4 100644 --- a/src/export.py +++ b/src/export.py @@ -51,12 +51,15 @@ def export_entry(entry): lexunit.setAttribute("id", entry.lexical_unit["id"]) lexunit.setAttribute("type", entry.lexical_unit['type']) for lexeme in entry.lexical_unit["lexemes"]: - component = doc.createElement('component') lexeme_xml = doc.createElement("lexeme") - component.appendChild(lexeme_xml) lexeme_xml.setAttribute("lexical_unit_lexeme_id", lexeme["id"]) lexeme_xml.textContent = lexeme["text"] - lexunit.appendChild(component) + if len(entry.lexical_unit["lexemes"] > 1): + component = doc.createElement('component') + component.appendChild(lexeme_xml) + lexunit.appendChild(component) + else: + lexunit.appendChild(lexeme_xml) head.appendChild(lexunit) @@ -218,6 +221,8 @@ def export_example_to_entry_xml(example, other_examples = None): lemma = doc.createElement("lemma") lemma.textContent = " ".join(comp.text for comp in example.components) lemma.setAttribute("type", "compound") + if example.inner.other_attributes['audio'] is not None: + lemma.setAttribute('audio', example.inner.other_attributes['audio']) headword.appendChild(lemma) homonymy = doc.createElement("homonymy") @@ -229,13 +234,13 @@ def export_example_to_entry_xml(example, other_examples = None): if example.inner.other_attributes['structure_id'] != None and len(example.components) <= 3: lexical_unit.setAttribute("id", example.inner.other_attributes['structure_id']) - for comp in example.components: - comp_xml = doc.createElement("component") lexeme = doc.createElement("lexeme") lexeme.textContent = comp.text - comp_xml.appendChild(lexeme) + comp_xml = doc.createElement("component") lexical_unit.appendChild(comp_xml) + comp_xml.appendChild(lexeme) + grammar = doc.createElement("grammar") category = doc.createElement("category")