finished
This commit is contained in:
parent
bd4e64f818
commit
5e741343c3
|
@ -1,6 +1,6 @@
|
|||
from browser import document
|
||||
from model.tags import export_tag
|
||||
|
||||
from model.translation import Translation
|
||||
|
||||
def export_to_xml(model):
|
||||
xml_document = export_entry(model.entry)
|
||||
|
@ -146,6 +146,7 @@ def export_sense(doc, sense):
|
|||
|
||||
def export_translation_list(doc, py_parent, xml_parent):
|
||||
for cidx, cluster in enumerate(py_parent.translations):
|
||||
if len(cluster) > 0:
|
||||
for translation in cluster:
|
||||
translation_container = export_translation(doc, translation)
|
||||
translation_container.setAttribute("cluster", str(cidx + 1))
|
||||
|
@ -200,7 +201,6 @@ def _original_xml_query_selector(selector, entry, doc, parent_selector = selecto
|
|||
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")
|
||||
|
@ -227,8 +227,8 @@ def export_example_to_entry_xml(example):
|
|||
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'])
|
||||
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:
|
||||
comp_xml = doc.createElement("component")
|
||||
|
@ -263,7 +263,8 @@ def export_example_to_entry_xml(example):
|
|||
sense_label_list = doc.createElement("labelList")
|
||||
sense.appendChild(sense_label_list)
|
||||
|
||||
first_translation = example.translations[0][0]
|
||||
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
|
||||
|
@ -271,8 +272,6 @@ def export_example_to_entry_xml(example):
|
|||
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)
|
||||
|
@ -294,12 +293,11 @@ def export_example_to_entry_xml(example):
|
|||
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")
|
||||
if first_translation.translation is not "":
|
||||
translation = doc.createElement("translation")
|
||||
translation_container.appendChild(translation)
|
||||
|
||||
|
@ -311,18 +309,17 @@ def export_example_to_entry_xml(example):
|
|||
|
||||
if first_translation.source:
|
||||
translation.setAttribute("source", first_translation.source)
|
||||
first_translation_is_valid = True
|
||||
|
||||
if len(first_translation.explanationList) > 0 :
|
||||
_export_explanation_list(doc, first_translation.explanationList, translation)
|
||||
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:]
|
||||
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)
|
||||
|
||||
return doc
|
||||
# for comp in example.components:
|
||||
# if comp.role == "collocate":
|
||||
# self.headword = comp.role
|
||||
# break
|
||||
|
||||
# self.headword = example.
|
Loading…
Reference in New Issue
Block a user