|
|
|
@ -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("<entry />", "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.
|