homonymy basic implementation

This commit is contained in:
matic_t 2020-07-15 04:17:58 -07:00
parent e37cf198cf
commit a22490c0fc
8 changed files with 186 additions and 139 deletions

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,14 @@ def export_entry(entry):
headword.appendChild(headword_lemma) headword.appendChild(headword_lemma)
head.appendChild(headword) head.appendChild(headword)
homonyms = doc.createElement("homonymy")
headword.appendChild(homonyms)
for h in entry.homonymy:
homonymy = doc.createElement("homonymyFeature")
homonymy.textContent = h
homonyms.appendChild(homonymy)
# 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")

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

@ -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.generic_list_getter()
model.entry.homonymy = homonymy
class EditRelatedEntries(Message): class EditRelatedEntries(Message):
def update_model(self, model): def update_model(self, model):

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,6 +26,7 @@ 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")
@ -34,6 +36,7 @@ class Entry(Data):
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 = [v.textContent 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 +83,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 +94,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(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

@ -99,6 +99,13 @@ 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):
console.log(entry)
hget = lambda: entry.copy().homonymy
content = generic_list_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)