Merge pull request 'mt-additional-xml-shema-support' (#5) from mt-additional-xml-shema-support into master

Reviewed-on: #5
This commit is contained in:
matic_t 2020-08-05 10:04:53 +00:00
commit 2b2a2c4bd9
15 changed files with 322 additions and 223 deletions

View File

@ -4,10 +4,10 @@
############################################################################# #############################################################################
# Alter these variables # Alter these variables
#USERNAME= vps_sign_in(probably name@lexonomy.cjvt.si #USERNAME=vps_sign_in(probably name@lexonomy.cjvt.si
#VPS_PASSWORD= vps password #VPS_PASSWORD=vps password
#VPS_USERNAME= user name inside vps(probably name from @lexonomy) #VPS_USERNAME=user name inside vps(probably name from @lexonomy)
#API_KEY= $(cat path/to/api/token/file) #API_KEY=$(cat path/to/api/token/file)
# Exit if no argument is passed on run # Exit if no argument is passed on run
if [[ -z "$1" ]]; then if [[ -z "$1" ]]; then
@ -24,4 +24,4 @@ tar czf - ./config.json ./bundle.js ./local.js ./main.css ./main.html | ssh $USE
# Create a simlink on VPS that will enable specific plugin on https://lexonomy.cjvt.si/ # Create a simlink on VPS that will enable specific plugin on https://lexonomy.cjvt.si/
# Routes must be absolute or it doesn't work. # Routes must be absolute or it doesn't work.
ssh -t $USERNAME -p $VPS_PASSWORD "sudo ln -s /home/$VPS_USERNAME/plugins/$PLUGIN_NAME /home/ozbolt/plugins/$PLUGIN_NAME" ssh -t $USERNAME -p $VPS_PASSWORD "sudo -s unlink /home/ozbolt/plugins/$PLUGIN_NAME || true && sudo ln -s /home/$VPS_USERNAME/plugins/$PLUGIN_NAME /home/ozbolt/plugins/$PLUGIN_NAME"

View File

@ -4,7 +4,12 @@
<head> <head>
<status>LBS</status> <status>LBS</status>
<headword> <headword>
<lemma>aplikativen</lemma> <lemma>aplikativen3</lemma>
<homonymy>
<homonymyFeature name="pronunciation">bolníšnica</homonymyFeature>
<homonymyFeature name="blahblah">xyz</homonymyFeature>
<homonymyFeature name="bluhbluh">abc</homonymyFeature>
</homonymy>
</headword> </headword>
<grammar> <grammar>
<category>pridevnik</category> <category>pridevnik</category>

View File

@ -11,7 +11,6 @@ def export_to_xml(model):
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
@ -30,6 +29,17 @@ def export_entry(entry):
headword.appendChild(headword_lemma) headword.appendChild(headword_lemma)
head.appendChild(headword) head.appendChild(headword)
homonymy = doc.createElement("homonymy")
headword.appendChild(homonymy)
for hFeature in entry.homonymy:
feature = doc.createElement("homonymyFeature")
feature.textContent = hFeature.value
# 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({}) works uncorrectly in transcrypt
if len(entry.lexical_unit) > 0: if len(entry.lexical_unit) > 0:
lexunit = doc.createElement("lexicalUnit") lexunit = doc.createElement("lexicalUnit")
@ -140,6 +150,16 @@ def export_translation(doc, translation):
actual_t.setAttribute("source", translation.source) actual_t.setAttribute("source", translation.source)
translation_xml.appendChild(actual_t) translation_xml.appendChild(actual_t)
explanationList = doc.createElement("explanationList")
for explanation in translation.explanationList:
el = doc.createElement("explanation")
el.textContent = explanation
explanationList.appendChild(el)
translation_xml.appendChild(explanationList)
explanation = doc.createElement("explanation") explanation = doc.createElement("explanation")
explanation.textContent = translation.explanation explanation.textContent = translation.explanation
translation_xml.appendChild(explanation) translation_xml.appendChild(explanation)

View File

@ -1,11 +1,11 @@
from message.simple_messages import NoReset, Reset, ModalNotOkClose, ClickMessage, DataChgClickMessage, KeyboardPress, NoAction from message.simple_messages import NoReset, Reset, ModalNotOkClose, ClickMessage, DataChgClickMessage, KeyboardPress, NoAction
from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation
from message.show_messages import ShowEntryLabelsEdit, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowExampleEdit, ShowVariantsEdit, ShowRelatedEntriesEdit 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, EditRelatedEntries, EditEntryLabels, ExampleClusterEdit, ExampleClusterAdd 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.show_menu import ShowTranslationMenu, ShowSenseMenu, ShowExampleMenu
from message.sense_edit import SenseMoveUp, SenseMoveDown, SenseBin, AddMultiwordExample 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 ExampleMoveUp, ExampleMoveDown, ExampleBin, ExampleRoleChange, ExampleComponentSpace, ExampleComponentAdd, ExampleComponentRemove, EditExampleText, ToggleExamples, ToggleClusters
from message.delete_messages import DeleteComment, DeleteVariants, DeleteRelatedEntries, DeleteEntryLabels from message.delete_messages import DeleteComment, DeleteVariants, DeleteHomonymy, DeleteRelatedEntries, DeleteEntryLabels
from message.ske_messages import ShowSkeModal, SearchInSkeModal, SkeInsert from message.ske_messages import ShowSkeModal, SearchInSkeModal, SkeInsert
from message.message import msg, delayed_msg from message.message import msg, delayed_msg

View File

@ -9,6 +9,21 @@ def generic_list_getter():
result.append(result_candidate) result.append(result_candidate)
return result return result
# Formats data from inputs to name-value objects
def homonymy_list_getter():
result = []
for row in document.getElementsByClassName("label-list-row"):
value = row.querySelector(".value-input").value
name = row.querySelector(".name-input").value
if ("" in [name, value]):
continue
result.append({"name": name, "value": value})
return result
def label_list_getter(): def label_list_getter():
result = [] result = []
for row in document.getElementsByClassName("label-list-row"): for row in document.getElementsByClassName("label-list-row"):

View File

@ -18,6 +18,14 @@ class DeleteRelatedEntries(DeleteVariants):
pass pass
class DeleteHomonymy(NoReset):
def update_model(self, model):
for el in document.getElementsByClassName("list-adder-input"):
el.value = ""
class DeleteEntryLabels(NoReset): class DeleteEntryLabels(NoReset):
def update_model(self, model): def update_model(self, model):
for sel in document.getElementsByClassName("label-value"): for sel in document.getElementsByClassName("label-value"):

View File

@ -30,6 +30,12 @@ class ShowVariantsEdit(ClickMessage):
model.modal_set(lambda: modals.edit_variants(model.entry)) model.modal_set(lambda: modals.edit_variants(model.entry))
class ShowHomonymyEdit(ClickMessage):
def update_model(self, model):
model.entry.make_copy()
model.modal_set(lambda: modals.edit_homonymy(model.entry))
class ShowRelatedEntriesEdit(ClickMessage): class ShowRelatedEntriesEdit(ClickMessage):
def update_model(self, model): def update_model(self, model):
model.entry.make_copy() model.entry.make_copy()

View File

@ -88,6 +88,11 @@ class EditVariants(Message):
variants = common_accessors.generic_list_getter() variants = common_accessors.generic_list_getter()
model.entry.variants = variants model.entry.variants = variants
class EditHomonymy(Message):
def update_model(self, model):
homonymy = common_accessors.homonymy_list_getter()
model.entry.homonymy = homonymy
class EditRelatedEntries(Message): class EditRelatedEntries(Message):
def update_model(self, model): def update_model(self, model):

View File

@ -13,7 +13,8 @@ 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
self.translation.explanation = document.getElementById("ete").value # This could be dangerous if generic_list_getter is getting data from any other list as well.
self.translation.explanationList = common_accessors.generic_list_getter()
# 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()

View File

@ -12,6 +12,7 @@ class Entry(Data):
def __init__(self): def __init__(self):
self.status = "" self.status = ""
self.headword = "" self.headword = ""
self.homonymy = []
self.headword_type = None self.headword_type = None
self.grammar = "" self.grammar = ""
self.comment = "" self.comment = ""
@ -25,15 +26,16 @@ class Entry(Data):
def import_xml(self, entry_xml): def import_xml(self, 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")
grammar = entry_xml.querySelector("head grammar category") grammar = entry_xml.querySelector("head grammar category")
comment = entry_xml.querySelector("head comment") comment = entry_xml.querySelector("head comment")
self.status = status.textContent if status else "" self.status = status.textContent if status else ""
self.headword = headword.textContent if headword else "" self.headword = headword.textContent if headword else ""
self.headword_type = headword.getAttribute("type") if headword else None self.headword_type = headword.getAttribute("type") if headword else None
self.grammar = grammar.textContent if grammar else "" self.grammar = grammar.textContent if grammar else ""
self.comment = comment.textContent if comment else "" self.comment = comment.textContent if comment else ""
self.variants = [v.textContent for v in entry_xml.querySelectorAll("head variantList variant")] self.variants = [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")] 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")
@ -80,7 +82,8 @@ class Entry(Data):
h("button.normal", clk(M.ShowVariantsEdit), "Variante"), h("button.normal", clk(M.ShowVariantsEdit), "Variante"),
h("button.success", clk(M.ShowRelatedEntriesEdit), "Povezano"), h("button.success", clk(M.ShowRelatedEntriesEdit), "Povezano"),
h("button.success", clk(M.ShowEntryLabelsEdit), "Oznake"), h("button.success", clk(M.ShowEntryLabelsEdit), "Oznake"),
h("button.normal", clk(M.ShowCommentEdit), "Opombe")] h("button.normal", clk(M.ShowCommentEdit), "Opombe"),
h("button.normal", clk(M.ShowHomonymyEdit), "Homonomije"),]
view_buttons = [] view_buttons = []
view_table = [] view_table = []
@ -90,6 +93,11 @@ class Entry(Data):
else: else:
view_table.append((buttons[0], ", ".join(self.variants))) view_table.append((buttons[0], ", ".join(self.variants)))
if len(self.homonymy) == 0:
view_buttons.append(buttons[4])
else:
view_table.append((buttons[4], ", ".join((h["name"] + ": " + h.value) for h in self.homonymy)))
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 File

@ -23,7 +23,7 @@ class ComponentLexeme(Data):
if xml.hasAttribute("space"): if xml.hasAttribute("space"):
self.no_space = xml.getAttribute("space") == "false" self.no_space = xml.getAttribute("space") == "false"
for oth_attr in ["lexical_unit_lexeme_id", "slolex", "kol"]: for oth_attr in ["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)

View File

@ -33,6 +33,7 @@ class Translation(Data):
self.source = "" self.source = ""
self.targetLang = "" self.targetLang = ""
self.explanation = "" self.explanation = ""
self.explanationList = []
self.tags = [] self.tags = []
def import_xml(self, translation_xml): def import_xml(self, translation_xml):
@ -43,11 +44,15 @@ class Translation(Data):
self.source = translation.getAttribute("source") if translation.hasAttribute("source") else "" self.source = translation.getAttribute("source") if translation.hasAttribute("source") else ""
self.targetLang = translation.getAttribute("targetLang") if translation.hasAttribute("targetLang") else "" self.targetLang = translation.getAttribute("targetLang") if translation.hasAttribute("targetLang") else ""
explanationList = translation_xml.querySelectorAll("explanationList explanation")
for explanation in explanationList:
self.explanationList.append(explanation.textContent if explanation else "")
explanation = translation_xml.querySelector("explanation") explanation = translation_xml.querySelector("explanation")
self.explanation = explanation.textContent if explanation else "" self.explanation = explanation.textContent if explanation else ""
self.tags = import_label_list("labelList label", translation_xml) self.tags = import_label_list("labelList label", translation_xml)
def view(self, model): def view(self, model):
elements = [] elements = []
@ -62,7 +67,9 @@ class Translation(Data):
elements.append(h("span.translation-source", {}, self.source)) elements.append(h("span.translation-source", {}, self.source))
explanation_class = ".translation-explanation" if self.translation else "" explanation_class = ".translation-explanation" if self.translation else ""
elements.append(h("span{}".format(explanation_class), {}, self.explanation))
# elements.append(h("span{}".format(explanation_class), {}, self.explanations))
elements.append(h("span{}".format(explanation_class), {}, ", ".join(self.explanationList)))
return h("div.translation-div", {"on": {"click": M.msg(M.ShowTranslationMenu, self) }}, elements) return h("div.translation-div", {"on": {"click": M.msg(M.ShowTranslationMenu, self) }}, elements)

View File

@ -47,6 +47,25 @@ def generic_list_editor(title, element_list_getter):
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 split_line2(left, right):
cls = "flex.two{}".format(".label-list-row")
return h("div.{}".format(cls), {}, [
h("div.half", {}, left), h("div.half", {}, right)])
content = [h("p", {}, title)]
for i, feature in enumerate(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}}, ""))
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))
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, current_labels)}}, "+"))
return content
def label_list_editor(current_labels, add_label_message_class): def label_list_editor(current_labels, add_label_message_class):
def split_line3(left, center, right, is_llr=True): def split_line3(left, center, right, is_llr=True):

View File

@ -19,10 +19,9 @@ def edit_translation(translation, parent, cluster_idx, num_clusters, cls):
# first line: transalation itself # first line: transalation itself
content.extend([ content.extend([
split_line2("Prevedek:", split_line2("Prevedek:", h("textarea#etv", {"props": {"value": translation.translation}}, ""))])
h("textarea#etv", {"props": {"value": translation.translation}}, "")),
split_line2("Razlaga:", content.extend(generic_list_editor("Razlage:", lambda: translation.explanationList))
h("textarea#ete", {"props": {"value": translation.explanation}}, ""))])
# cluster number # cluster number
options = [h("option", {"props": {"selected": idx == cluster_idx}}, str(idx + 1)) for idx in range(num_clusters + 1)] options = [h("option", {"props": {"selected": idx == cluster_idx}}, str(idx + 1)) for idx in range(num_clusters + 1)]
@ -99,6 +98,12 @@ def edit_variants(entry):
return modal_template(content, "Add or remove variants", (message.EditVariants,), (message.DeleteVariants,)) return modal_template(content, "Add or remove variants", (message.EditVariants,), (message.DeleteVariants,))
def edit_homonymy(entry):
hget = lambda: entry.copy().homonymy
content = homonymy_editor("Homonymy", hget)
return modal_template(content, "Add or remove homonymy features", (message.EditHomonymy,), (message.DeleteHomonymy,))
def edit_related_entries(entry): def edit_related_entries(entry):
reget = lambda: entry.copy().related_entries reget = lambda: entry.copy().related_entries
content = generic_list_editor("Related entries", reget) content = generic_list_editor("Related entries", reget)