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

@@ -12,6 +12,7 @@ class Entry(Data):
def __init__(self):
self.status = ""
self.headword = ""
self.homonymy = []
self.headword_type = None
self.grammar = ""
self.comment = ""
@@ -21,26 +22,28 @@ class Entry(Data):
self.measure = {}
self.labels = []
self.senses = []
def import_xml(self, entry_xml):
status = entry_xml.querySelector("head status")
headword = entry_xml.querySelector("head headword lemma")
grammar = entry_xml.querySelector("head grammar category")
comment = entry_xml.querySelector("head comment")
self.status = status.textContent if status else ""
self.headword = headword.textContent if headword else ""
self.headword_type = headword.getAttribute("type") if headword else None
self.grammar = grammar.textContent if grammar else ""
self.comment = comment.textContent if comment else ""
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")]
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
measure = entry_xml.querySelector("measureList measure")
if measure:
self.measure["source"] = measure.getAttribute("source")
@@ -48,19 +51,19 @@ class Entry(Data):
self.measure["text"] = measure.textContent
self.labels = import_label_list("head labelList label", entry_xml)
for i, sense_xml in enumerate(entry_xml.querySelectorAll("body senseList sense")):
sense = Sense()
sense.import_xml(sense_xml, i)
self.senses.append(sense)
def view(self, model):
view_sense_list = [sense.view(model, idx) for idx, sense in enumerate(self.senses)]
buttons_left = self._view_button_section(model)
buttons_right = View.view_toggle_buttons(model)
return h("div#entry", {}, [
h("div#entry-status", {}, self.status),
h("div#entry-header", {}, [
@@ -72,51 +75,57 @@ class Entry(Data):
h("div.one-fifth", {}, buttons_right)]),
h("div#sense-container", {}, view_sense_list),
h("button.add-button", {"on": {"click": M.msg(M.AddSense)}}, "+")])
def _view_button_section(self, model):
clk = lambda cls: {"on": {"click": M.msg(cls)}}
buttons = [
h("button.normal", clk(M.ShowVariantsEdit), "Variante"),
h("button.success", clk(M.ShowRelatedEntriesEdit), "Povezano"),
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_table = []
if len(self.variants) == 0:
view_buttons.append(buttons[0])
else:
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:
view_buttons.append(buttons[1])
else:
view_table.append((buttons[1], ", ".join(self.related_entries)))
if len(self.labels) == 0:
view_buttons.append(buttons[2])
else:
labels = ", ".join([clean_label(val) for _, val in self.labels])
view_table.append((buttons[2], labels))
if self.comment == "":
view_buttons.append(buttons[3])
else:
view_table.append((buttons[3], self.comment))
table_rows = [
h("tr", {}, [ h("td", {}, btn), h("td", {}, content)])
h("tr", {}, [ h("td", {}, btn), h("td", {}, content)])
for btn, content in view_table]
view_buttons.append(h("table", {}, table_rows))
return h("div", {}, view_buttons)
def get_measure_text(self):
return self.measure["text"] if "text" in self.measure else ""
def remove_translation(self, translation):
for sense in self.senses:
for cluster in sense.translations:
@@ -128,4 +137,4 @@ class Entry(Data):
if translation in cluster:
cluster.remove(translation)
return