|
|
|
from model.sense import Sense
|
|
|
|
from model.editable import Editable
|
|
|
|
from model.tags import TAGS
|
|
|
|
|
|
|
|
class Entry(Editable):
|
|
|
|
def __init__(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.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.lexical_unit = {}
|
|
|
|
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
|
|
|
|
|
|
|
|
self.measure = {}
|
|
|
|
measure = entry_xml.querySelector("measureList measure")
|
|
|
|
if measure:
|
|
|
|
self.measure["source"] = measure.getAttribute("source")
|
|
|
|
self.measure["type"] = measure.getAttribute("type")
|
|
|
|
self.measure["text"] = measure.textContent
|
|
|
|
|
|
|
|
self.labels = []
|
|
|
|
for tag_xml in entry_xml.querySelectorAll("head labelList label"):
|
|
|
|
t_type = tag_xml.getAttribute("type")
|
|
|
|
t_value = tag_xml.textContent
|
|
|
|
|
|
|
|
if t_type not in TAGS:
|
|
|
|
# using some default
|
|
|
|
t_type = TAGS.keys()[0]
|
|
|
|
|
|
|
|
self.labels.append((t_type, t_value))
|
|
|
|
|
|
|
|
self.senses = [Sense(sense_xml) for sense_xml in
|
|
|
|
entry_xml.querySelectorAll("body senseList sense")]
|
|
|
|
|
|
|
|
def get_measure_text(self):
|
|
|
|
return self.measure["text"] if "text" in self.measure else ""
|
|
|
|
|