|
|
@ -1,6 +1,6 @@
|
|
|
|
from browser import document
|
|
|
|
from browser import document
|
|
|
|
from model.tags import export_tag
|
|
|
|
from model.tags import export_tag
|
|
|
|
|
|
|
|
from model.translation import Translation
|
|
|
|
|
|
|
|
|
|
|
|
def export_to_xml(model):
|
|
|
|
def export_to_xml(model):
|
|
|
|
xml_document = export_entry(model.entry)
|
|
|
|
xml_document = export_entry(model.entry)
|
|
|
@ -46,15 +46,20 @@ def export_entry(entry):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# if({}) works uncorrectly in transcrypt
|
|
|
|
# if({}) works uncorrectly in transcrypt
|
|
|
|
if len(entry.lexical_unit) > 0:
|
|
|
|
if len(entry.lexical_unit) > 0 and len(entry.lexical_unit['lexemes']) > 0:
|
|
|
|
lexunit = doc.createElement("lexicalUnit")
|
|
|
|
lexunit = doc.createElement("lexicalUnit")
|
|
|
|
lexunit.setAttribute("id", entry.lexical_unit["id"])
|
|
|
|
lexunit.setAttribute("id", entry.lexical_unit["id"])
|
|
|
|
lexunit.setAttribute("type", "single")
|
|
|
|
lexunit.setAttribute("type", entry.lexical_unit['type'])
|
|
|
|
lexeme = doc.createElement("lexeme")
|
|
|
|
for lexeme in entry.lexical_unit["lexemes"]:
|
|
|
|
lexeme.setAttribute("lexical_unit_lexeme_id", entry.lexical_unit["id"])
|
|
|
|
lexeme_xml = doc.createElement("lexeme")
|
|
|
|
lexeme.textContent = entry.lexical_unit["text"]
|
|
|
|
lexeme_xml.setAttribute("lexical_unit_lexeme_id", lexeme["id"])
|
|
|
|
|
|
|
|
lexeme_xml.textContent = lexeme["text"]
|
|
|
|
lexunit.appendChild(lexeme)
|
|
|
|
if len(entry.lexical_unit["lexemes"] > 1):
|
|
|
|
|
|
|
|
component = doc.createElement('component')
|
|
|
|
|
|
|
|
component.appendChild(lexeme_xml)
|
|
|
|
|
|
|
|
lexunit.appendChild(component)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
lexunit.appendChild(lexeme_xml)
|
|
|
|
head.appendChild(lexunit)
|
|
|
|
head.appendChild(lexunit)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -144,6 +149,7 @@ def export_sense(doc, sense):
|
|
|
|
|
|
|
|
|
|
|
|
def export_translation_list(doc, py_parent, xml_parent):
|
|
|
|
def export_translation_list(doc, py_parent, xml_parent):
|
|
|
|
for cidx, cluster in enumerate(py_parent.translations):
|
|
|
|
for cidx, cluster in enumerate(py_parent.translations):
|
|
|
|
|
|
|
|
if len(cluster) > 0:
|
|
|
|
for translation in cluster:
|
|
|
|
for translation in cluster:
|
|
|
|
translation_container = export_translation(doc, translation)
|
|
|
|
translation_container = export_translation(doc, translation)
|
|
|
|
translation_container.setAttribute("cluster", str(cidx + 1))
|
|
|
|
translation_container.setAttribute("cluster", str(cidx + 1))
|
|
|
@ -190,3 +196,145 @@ def _export_label_list(doc, lst):
|
|
|
|
label_el.setAttribute('type', key)
|
|
|
|
label_el.setAttribute('type', key)
|
|
|
|
result.appendChild(label_el)
|
|
|
|
result.appendChild(label_el)
|
|
|
|
return result
|
|
|
|
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, other_examples = None):
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
|
|
|
if example.inner.other_attributes['audio'] is not None:
|
|
|
|
|
|
|
|
lemma.setAttribute('audio', example.inner.other_attributes['audio'])
|
|
|
|
|
|
|
|
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 and len(example.components) <= 3:
|
|
|
|
|
|
|
|
lexical_unit.setAttribute("id", example.inner.other_attributes['structure_id'])
|
|
|
|
|
|
|
|
for comp in example.components:
|
|
|
|
|
|
|
|
lexeme = doc.createElement("lexeme")
|
|
|
|
|
|
|
|
lexeme.textContent = comp.text
|
|
|
|
|
|
|
|
comp_xml = doc.createElement("component")
|
|
|
|
|
|
|
|
lexical_unit.appendChild(comp_xml)
|
|
|
|
|
|
|
|
comp_xml.appendChild(lexeme)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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] if len(example.translations) > 0 and len(example.translations[0]) > 0 else Translation()
|
|
|
|
|
|
|
|
first_translation_is_valid = False
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(translation_label_list) > 0:
|
|
|
|
|
|
|
|
translation_container.appendChild(translation_label_list)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if first_translation.translation is not "":
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
first_translation_is_valid = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(first_translation.explanationList) > 0 :
|
|
|
|
|
|
|
|
explanation_list = _export_explanation_list(doc, first_translation.explanationList)
|
|
|
|
|
|
|
|
translation_container.appendChild(explanation_list)
|
|
|
|
|
|
|
|
first_translation_is_valid = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if first_translation_is_valid:
|
|
|
|
|
|
|
|
translation_container_list.appendChild(translation_container)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
example.translations[0] = example.translations[0][1:] if len(example.translations) > 0 and len(example.translations[0]) > 0 else example.translations[0]
|
|
|
|
|
|
|
|
export_translation_list(doc, example, translation_container_list)
|
|
|
|
|
|
|
|
if other_examples is not None:
|
|
|
|
|
|
|
|
example_container_list = doc.createElement("exampleContainerList")
|
|
|
|
|
|
|
|
sense.appendChild(example_container_list)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for example in other_examples:
|
|
|
|
|
|
|
|
example_container = example.export(doc)
|
|
|
|
|
|
|
|
translation_container_list = doc.createElement("translationContainerList")
|
|
|
|
|
|
|
|
export_translation_list(doc, example, translation_container_list)
|
|
|
|
|
|
|
|
example_container.appendChild(translation_container_list)
|
|
|
|
|
|
|
|
example_container_list.appendChild(example_container)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return doc
|