Compare commits
20 Commits
mt-homonym
...
mt-additio
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d513ec8eaa | ||
|
|
5fe2bb62bb | ||
|
|
85bf0473e5 | ||
|
|
8049f5ed95 | ||
|
|
48c51c38de | ||
|
|
094cc7afcf | ||
|
|
410054cdd6 | ||
|
|
ec811028ab | ||
|
|
752ec44d43 | ||
|
|
83396ef8a0 | ||
|
|
efe4d07464 | ||
|
|
1770932a14 | ||
|
|
2b2a2c4bd9 | ||
|
|
a07b35c6a8 | ||
|
|
ad83665b0d | ||
|
|
0c62cbe4d8 | ||
| a7f85accce | |||
| 3926d1a199 | |||
|
|
964dc3f788 | ||
|
|
8b7c282fdf |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -10,5 +10,5 @@ build/*
|
|||||||
# using kdev4, works fairly nicely!
|
# using kdev4, works fairly nicely!
|
||||||
.kdev4
|
.kdev4
|
||||||
**/*.kdev4
|
**/*.kdev4
|
||||||
|
remote
|
||||||
|
|
||||||
|
|||||||
@@ -64,13 +64,13 @@
|
|||||||
margin-bottom: 1em;
|
margin-bottom: 1em;
|
||||||
|
|
||||||
#headword {
|
#headword {
|
||||||
font-size: 1.2em;
|
font-size: 1.2em;
|
||||||
color: @darkred;
|
color: @darkred;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
#grammar {
|
#grammar {
|
||||||
color: @gray;
|
color: @gray;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
margin-left: 1em;
|
margin-left: 1em;
|
||||||
}
|
}
|
||||||
@@ -90,8 +90,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#sense-container {
|
#sense-container {
|
||||||
border-top: 1px dotted #999999;
|
border-top: 1px dotted #999999;
|
||||||
padding-top: 0.5em;
|
padding-top: 0.5em;
|
||||||
margin-top: 0.5em;
|
margin-top: 0.5em;
|
||||||
|
|
||||||
.sense-num {
|
.sense-num {
|
||||||
@@ -156,16 +156,7 @@
|
|||||||
vertical-align: super;
|
vertical-align: super;
|
||||||
font-size: 0.7em;
|
font-size: 0.7em;
|
||||||
}
|
}
|
||||||
.translation-explanation:not(:empty) {
|
|
||||||
font-style: italic;
|
|
||||||
|
|
||||||
&:before {
|
|
||||||
content: '[';
|
|
||||||
}
|
|
||||||
&:after {
|
|
||||||
content: ']';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.translation-add {
|
.translation-add {
|
||||||
@@ -175,10 +166,24 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.explanations:not(:empty) {
|
||||||
|
font-style: italic;
|
||||||
|
|
||||||
|
&:not(.solo) {
|
||||||
|
&:before {
|
||||||
|
content: '[';
|
||||||
|
}
|
||||||
|
|
||||||
|
&:after {
|
||||||
|
content: ']';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.example {
|
.example {
|
||||||
clear: left;
|
clear: left;
|
||||||
margin-left: 1em;
|
margin-left: 1em;
|
||||||
|
|
||||||
.example-dot, .example-rest {
|
.example-dot, .example-rest {
|
||||||
float: left;
|
float: left;
|
||||||
max-width: 90%;
|
max-width: 90%;
|
||||||
@@ -242,7 +247,7 @@
|
|||||||
|
|
||||||
// if span left of input it is just too high, this is a fix
|
// if span left of input it is just too high, this is a fix
|
||||||
.span-left-of-input {
|
.span-left-of-input {
|
||||||
margin-top: 0.3em;
|
margin-top: 0.3em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -257,7 +262,7 @@
|
|||||||
.example-cluster {
|
.example-cluster {
|
||||||
color: @blue;
|
color: @blue;
|
||||||
}
|
}
|
||||||
.example-logdice {
|
.example-logdice {
|
||||||
color: @gray;
|
color: @gray;
|
||||||
}
|
}
|
||||||
.example-frequency {
|
.example-frequency {
|
||||||
@@ -289,7 +294,7 @@
|
|||||||
.example-component-none {
|
.example-component-none {
|
||||||
color: @gray;
|
color: @gray;
|
||||||
}
|
}
|
||||||
|
|
||||||
.example-component-no-space {
|
.example-component-no-space {
|
||||||
color: @silver;
|
color: @silver;
|
||||||
}
|
}
|
||||||
@@ -313,7 +318,7 @@
|
|||||||
background-color: rgba(0,0, 0, 0.01);
|
background-color: rgba(0,0, 0, 0.01);
|
||||||
padding: 0.5em;
|
padding: 0.5em;
|
||||||
border: 2px solid gray;
|
border: 2px solid gray;
|
||||||
margin: 1em;
|
margin: 1em;
|
||||||
|
|
||||||
.ske-line {
|
.ske-line {
|
||||||
display: block;
|
display: block;
|
||||||
@@ -325,13 +330,13 @@
|
|||||||
|
|
||||||
.grey1 {
|
.grey1 {
|
||||||
margin-left: 0.3em;
|
margin-left: 0.3em;
|
||||||
background-color: @silver;
|
background-color: @silver;
|
||||||
color: @black;
|
color: @black;
|
||||||
}
|
}
|
||||||
.grey2 {
|
.grey2 {
|
||||||
margin-left: 0.3em;
|
margin-left: 0.3em;
|
||||||
background-color: @black;
|
background-color: @black;
|
||||||
color: @silver;
|
color: @silver;
|
||||||
}
|
}
|
||||||
|
|
||||||
.no-gf2-info {
|
.no-gf2-info {
|
||||||
@@ -374,7 +379,7 @@
|
|||||||
// overflow: scroll;
|
// overflow: scroll;
|
||||||
// border: 2px solid red;
|
// border: 2px solid red;
|
||||||
// height: 10em;
|
// height: 10em;
|
||||||
//
|
//
|
||||||
// :nth-last-child(odd) {
|
// :nth-last-child(odd) {
|
||||||
// background-color: lightgray;
|
// background-color: lightgray;
|
||||||
// }
|
// }
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from model.tags import export_tag
|
|||||||
def export_to_xml(model):
|
def export_to_xml(model):
|
||||||
xml_document = export_entry(model.entry)
|
xml_document = export_entry(model.entry)
|
||||||
serializer = __new__(XMLSerializer())
|
serializer = __new__(XMLSerializer())
|
||||||
return serializer.serializeToString(xml_document);
|
return serializer.serializeToString(xml_document)
|
||||||
|
|
||||||
|
|
||||||
def export_entry(entry):
|
def export_entry(entry):
|
||||||
@@ -23,9 +23,14 @@ def export_entry(entry):
|
|||||||
|
|
||||||
headword = doc.createElement("headword")
|
headword = doc.createElement("headword")
|
||||||
headword_lemma = doc.createElement("lemma")
|
headword_lemma = doc.createElement("lemma")
|
||||||
|
|
||||||
|
# headword_lemma = entry.original_xml.querySelector("head headword lemma")
|
||||||
|
|
||||||
headword_lemma.textContent = entry.headword
|
headword_lemma.textContent = entry.headword
|
||||||
if entry.headword_type is not None:
|
if entry.headword_type is not None:
|
||||||
headword_lemma.setAttribute("type", entry.headword_type)
|
headword_lemma.setAttribute("type", entry.headword_type)
|
||||||
|
if entry.headword_audio is not None:
|
||||||
|
headword_lemma.setAttribute("audio", entry.headword_audio)
|
||||||
headword.appendChild(headword_lemma)
|
headword.appendChild(headword_lemma)
|
||||||
head.appendChild(headword)
|
head.appendChild(headword)
|
||||||
|
|
||||||
@@ -52,11 +57,18 @@ def export_entry(entry):
|
|||||||
lexunit.appendChild(lexeme)
|
lexunit.appendChild(lexeme)
|
||||||
head.appendChild(lexunit)
|
head.appendChild(lexunit)
|
||||||
|
|
||||||
grammar = doc.createElement("grammar")
|
# Example of keeping original xml and adding changes to it only
|
||||||
grammar_category = doc.createElement("category")
|
grammar_category = entry.original_xml.querySelector("head grammar category")
|
||||||
|
if grammar_category is None:
|
||||||
|
grammar = doc.createElement("grammar")
|
||||||
|
grammar_category = doc.createElement("category")
|
||||||
|
grammar.appendChild(grammar_category)
|
||||||
|
entry.original_xml.querySelector("head").appendChild(grammar_category)
|
||||||
|
|
||||||
grammar_category.textContent = entry.grammar
|
grammar_category.textContent = entry.grammar
|
||||||
grammar.appendChild(grammar_category)
|
|
||||||
head.appendChild(grammar)
|
head.appendChild(entry.original_xml.querySelector("head grammar"))
|
||||||
|
|
||||||
|
|
||||||
if len(entry.measure) > 0:
|
if len(entry.measure) > 0:
|
||||||
measure_list = doc.createElement("measureList")
|
measure_list = doc.createElement("measureList")
|
||||||
@@ -125,7 +137,9 @@ def export_sense(doc, sense):
|
|||||||
|
|
||||||
for example in sense.examples:
|
for example in sense.examples:
|
||||||
example_container = example.export(doc)
|
example_container = example.export(doc)
|
||||||
export_translation_list(doc, example, example_container)
|
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)
|
example_container_list.appendChild(example_container)
|
||||||
|
|
||||||
return sense_xml
|
return sense_xml
|
||||||
@@ -146,16 +160,27 @@ def export_translation(doc, translation):
|
|||||||
actual_t.textContent = translation.translation
|
actual_t.textContent = translation.translation
|
||||||
actual_t.setAttribute("targetLang", translation.targetLang)
|
actual_t.setAttribute("targetLang", translation.targetLang)
|
||||||
|
|
||||||
|
if translation.audio:
|
||||||
|
actual_t.setAttribute("audio", translation.audio)
|
||||||
|
|
||||||
if translation.source:
|
if translation.source:
|
||||||
actual_t.setAttribute("source", translation.source)
|
actual_t.setAttribute("source", translation.source)
|
||||||
translation_xml.appendChild(actual_t)
|
translation_xml.appendChild(actual_t)
|
||||||
|
|
||||||
explanation = doc.createElement("explanation")
|
if len(translation.explanationList) > 0 :
|
||||||
explanation.textContent = translation.explanation
|
explanationList = _export_explanation_list(doc, translation.explanationList)
|
||||||
translation_xml.appendChild(explanation)
|
translation_xml.appendChild(explanationList)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return translation_xml
|
return translation_xml
|
||||||
|
|
||||||
|
def _export_explanation_list(doc, lst):
|
||||||
|
result = doc.createElement('explanationList')
|
||||||
|
for explanation in lst:
|
||||||
|
result.appendChild(explanation.export(doc))
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
def _export_label_list(doc, lst):
|
def _export_label_list(doc, lst):
|
||||||
result = doc.createElement("labelList")
|
result = doc.createElement("labelList")
|
||||||
|
|||||||
@@ -34,19 +34,30 @@ def build_structure_conversions():
|
|||||||
structure_conversions.append((__new__(RegExp(vfrom, 'u')), vto_name, vto_id))
|
structure_conversions.append((__new__(RegExp(vfrom, 'u')), vto_name, vto_id))
|
||||||
|
|
||||||
|
|
||||||
def convert_structure(structure):
|
def convert_structure(structure, type):
|
||||||
if structure_conversions is None:
|
if structure_conversions is None:
|
||||||
build_structure_conversions()
|
build_structure_conversions()
|
||||||
|
|
||||||
for vfrom, vto_name, vto_id in structure_conversions:
|
for vfrom, vto_name, vto_id in structure_conversions:
|
||||||
match = structure.match(vfrom)
|
match = structure.match(vfrom)
|
||||||
|
# fix for ids 65, 66, 67 which instead matched with 64
|
||||||
|
if match and vto_id == '64' and '-s' in type:
|
||||||
|
vto_name = 's0-vp-s0'
|
||||||
|
vto_id = '65'
|
||||||
|
elif match and vto_id == '64' and '-g' in type:
|
||||||
|
vto_name = 'gg-vp-gg'
|
||||||
|
vto_id = '66'
|
||||||
|
elif match and vto_id == '64' and '-r' in type:
|
||||||
|
vto_name = 'r-vp-r'
|
||||||
|
vto_id = '67'
|
||||||
|
|
||||||
if match:
|
if match:
|
||||||
# we need to remove replace alias here as we want to use javascript's one
|
# we need to remove replace alias here as we want to use javascript's one
|
||||||
__pragma__('noalias', 'replace')
|
__pragma__('noalias', 'replace')
|
||||||
result = structure.replace(vfrom, vto_name).strip()
|
result = structure.replace(vfrom, vto_name).strip()
|
||||||
__pragma__('alias', 'replace', "py_replace")
|
__pragma__('alias', 'replace', "py_replace")
|
||||||
|
|
||||||
return result, vto_id
|
return result, vto_id
|
||||||
|
|
||||||
window.console.log("Unknown structure: ", structure)
|
window.console.log("Unknown structure: ", structure)
|
||||||
return None
|
return 'N/A', '/'
|
||||||
|
|||||||
@@ -10,16 +10,19 @@ def generic_list_getter():
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
# Formats data from inputs to name-value objects
|
# Formats data from inputs to name-value objects
|
||||||
def homonymy_list_getter():
|
def double_list_getter(firstParameter, secondParameter, allowEmptyField = False):
|
||||||
result = []
|
result = []
|
||||||
for row in document.getElementsByClassName("label-list-row"):
|
for row in document.getElementsByClassName("double-list-row"):
|
||||||
value = row.querySelector(".value-input").value
|
firstValue = row.querySelector("." + firstParameter + "-input").value
|
||||||
name = row.querySelector(".name-input").value
|
secondValue = row.querySelector("." + secondParameter + "-input").value
|
||||||
|
|
||||||
if ("" in [name, value]):
|
if (allowEmptyField is False and '' in [firstValue, secondValue]):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
result.append({"name": name, "value": value})
|
if (allowEmptyField is True and all('' == value or value.isspace() for value in [firstValue, secondValue])):
|
||||||
|
continue
|
||||||
|
|
||||||
|
result.append({firstParameter: firstValue, secondParameter: secondValue})
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ class EditVariants(Message):
|
|||||||
|
|
||||||
class EditHomonymy(Message):
|
class EditHomonymy(Message):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
homonymy = common_accessors.homonymy_list_getter()
|
homonymy = common_accessors.double_list_getter("value", "name")
|
||||||
model.entry.homonymy = homonymy
|
model.entry.homonymy = homonymy
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ class SkeExample:
|
|||||||
self.mid = ""
|
self.mid = ""
|
||||||
self.s_id = ""
|
self.s_id = ""
|
||||||
self.gf2_good = None
|
self.gf2_good = None
|
||||||
|
self.gf2_check = False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fromLine(line):
|
def fromLine(line):
|
||||||
@@ -58,15 +59,7 @@ class SkeCollocation:
|
|||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
self.word = data.word
|
self.word = data.word
|
||||||
self.frequency = data.count
|
self.frequency = data.count
|
||||||
|
self.structure_name, self.structure_id = convert_structure(data.gramrel, data.lempos)
|
||||||
info = convert_structure(data.gramrel)
|
|
||||||
if info is None:
|
|
||||||
self.structure_name = None
|
|
||||||
self.structure_id = None
|
|
||||||
else:
|
|
||||||
self.structure_name = info[0]
|
|
||||||
self.structure_id = info[1]
|
|
||||||
|
|
||||||
|
|
||||||
self.other = {"score": data.score, "cm": data.cm}
|
self.other = {"score": data.score, "cm": data.cm}
|
||||||
|
|
||||||
@@ -79,7 +72,7 @@ class SkeCollocation:
|
|||||||
h("span.grey1", {}, self.other["cm"]),
|
h("span.grey1", {}, self.other["cm"]),
|
||||||
h("span", {}, ","),
|
h("span", {}, ","),
|
||||||
h("span.grey2", {}, self.structure_name)])]
|
h("span.grey2", {}, self.structure_name)])]
|
||||||
|
|
||||||
|
|
||||||
def get_parser(ske_index_type):
|
def get_parser(ske_index_type):
|
||||||
if ske_index_type == 0:
|
if ske_index_type == 0:
|
||||||
@@ -148,7 +141,7 @@ class SkeModal(ClickMessage):
|
|||||||
elif type(data) is list:
|
elif type(data) is list:
|
||||||
window.console.log(data)
|
window.console.log(data)
|
||||||
# check if gf2 examples are loaded or not
|
# check if gf2 examples are loaded or not
|
||||||
if data[0].gf2_good is None:
|
if not data[0].gf2_check and type(data[0]) is SkeExample:
|
||||||
# we get the data, we have to match it with available data on our gf2 examples API
|
# we get the data, we have to match it with available data on our gf2 examples API
|
||||||
match_gf2_examples(data, page_num, search_term, ske_index)
|
match_gf2_examples(data, page_num, search_term, ske_index)
|
||||||
|
|
||||||
@@ -169,12 +162,18 @@ class SkeModalGf2Update(SkeModal):
|
|||||||
example.gf_good = False
|
example.gf_good = False
|
||||||
data_dict[example.s_id] = example
|
data_dict[example.s_id] = example
|
||||||
|
|
||||||
|
bad_response = dict(response_data["bad"])
|
||||||
|
for gf_sid, gf_data in bad_response.items():
|
||||||
|
data_dict[gf_sid].gf2_good = None
|
||||||
|
data_dict[gf_sid].gf2_check = True
|
||||||
|
|
||||||
good_response = dict(response_data["good"])
|
good_response = dict(response_data["good"])
|
||||||
for gf_sid, gf_data in good_response.items():
|
for gf_sid, gf_data in good_response.items():
|
||||||
data_dict[gf_sid].left = gf_data.left
|
data_dict[gf_sid].left = gf_data.left
|
||||||
data_dict[gf_sid].mid = gf_data.mid
|
data_dict[gf_sid].mid = gf_data.mid
|
||||||
data_dict[gf_sid].right = gf_data.right
|
data_dict[gf_sid].right = gf_data.right
|
||||||
data_dict[gf_sid].gf2_good = True
|
data_dict[gf_sid].gf2_good = True
|
||||||
|
data_dict[gf_sid].gf2_check = True
|
||||||
|
|
||||||
# changed data_dict, now we can redraw!
|
# changed data_dict, now we can redraw!
|
||||||
# just let it do its thing in update_model
|
# just let it do its thing in update_model
|
||||||
@@ -224,6 +223,8 @@ class SkeInsert(DataChgClickMessage):
|
|||||||
else:
|
else:
|
||||||
console.log("You really should not be here, my lady")
|
console.log("You really should not be here, my lady")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
model.reset()
|
||||||
|
|
||||||
def _as_corpus_example(self, example):
|
def _as_corpus_example(self, example):
|
||||||
new_example = Example()
|
new_example = Example()
|
||||||
|
|||||||
@@ -4,28 +4,35 @@ import message.common_accessors as common_accessors
|
|||||||
from browser import document, window
|
from browser import document, window
|
||||||
from model.translation import Translation
|
from model.translation import Translation
|
||||||
from model.sense import Sense
|
from model.sense import Sense
|
||||||
|
from model.explanation import Explanation
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class EditTranslation(DataChgClickMessage):
|
class EditTranslation(DataChgClickMessage):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
self.translation = self.get_arg(0, Translation)
|
self.translation = self.get_arg(0, Translation)
|
||||||
self.old_cluster_idx = self.get_arg(1, int)
|
self.old_cluster_idx = self.get_arg(1, int)
|
||||||
|
|
||||||
self.translation.translation = document.getElementById("etv").value
|
self.translation.translation = document.getElementById("etv").value
|
||||||
self.translation.explanation = document.getElementById("ete").value
|
# This could be dangerous if double_list_getter is getting data from any other list as well.
|
||||||
|
explanations = common_accessors.double_list_getter('value', 'language', True)
|
||||||
|
self.translation.explanationList = []
|
||||||
|
for entry in explanations:
|
||||||
|
explanation = Explanation()
|
||||||
|
explanation.value = entry.value
|
||||||
|
explanation.language = entry.language
|
||||||
|
self.translation.explanationList.append(explanation)
|
||||||
# common_accessors.label_list_getter()
|
# common_accessors.label_list_getter()
|
||||||
self.translation.tags = common_accessors.label_list_getter()
|
self.translation.tags = common_accessors.label_list_getter()
|
||||||
|
|
||||||
# check if empty, remove!
|
# check if empty, remove!
|
||||||
if self.translation.is_empty():
|
if self.translation.is_empty():
|
||||||
model.entry.remove_translation(self.translation)
|
model.entry.remove_translation(self.translation)
|
||||||
return
|
return
|
||||||
|
|
||||||
new_cluster_idx = int(document.getElementById("cluster-num").value) - 1
|
new_cluster_idx = int(document.getElementById("cluster-num").value) - 1
|
||||||
self.handle_cluster_change(new_cluster_idx, model)
|
self.handle_cluster_change(new_cluster_idx, model)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_translation_location(entry, translation):
|
def get_translation_location(entry, translation):
|
||||||
def find_in_clusters(parent):
|
def find_in_clusters(parent):
|
||||||
@@ -34,7 +41,7 @@ class EditTranslation(DataChgClickMessage):
|
|||||||
if search_translation == translation:
|
if search_translation == translation:
|
||||||
return (ci, ti), (parent, cluster)
|
return (ci, ti), (parent, cluster)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
for sense in entry.senses:
|
for sense in entry.senses:
|
||||||
res = find_in_clusters(sense)
|
res = find_in_clusters(sense)
|
||||||
if res is not None:
|
if res is not None:
|
||||||
@@ -43,21 +50,21 @@ class EditTranslation(DataChgClickMessage):
|
|||||||
res = find_in_clusters(example)
|
res = find_in_clusters(example)
|
||||||
if res is not None:
|
if res is not None:
|
||||||
return res
|
return res
|
||||||
|
|
||||||
window.console.log("should not be here...")
|
window.console.log("should not be here...")
|
||||||
|
|
||||||
|
|
||||||
def handle_cluster_change(self, new_cluster_idx, model):
|
def handle_cluster_change(self, new_cluster_idx, model):
|
||||||
if self.old_cluster_idx == new_cluster_idx:
|
if self.old_cluster_idx == new_cluster_idx:
|
||||||
return
|
return
|
||||||
|
|
||||||
(cidx, tidx), (parent, cluster) = EditTranslation.get_translation_location(model.entry, self.translation)
|
(cidx, tidx), (parent, cluster) = EditTranslation.get_translation_location(model.entry, self.translation)
|
||||||
self.do_cluster_change(parent, cluster, cidx, tidx, new_cluster_idx)
|
self.do_cluster_change(parent, cluster, cidx, tidx, new_cluster_idx)
|
||||||
|
|
||||||
def do_cluster_change(self, sense_or_example, cluster, cidx, tidx, new_cluster_idx):
|
def do_cluster_change(self, sense_or_example, cluster, cidx, tidx, new_cluster_idx):
|
||||||
# remove the translation from the old cluster
|
# remove the translation from the old cluster
|
||||||
cluster.splice(tidx, 1)
|
cluster.splice(tidx, 1)
|
||||||
|
|
||||||
# we maybe are creating a new cluster, handle that
|
# we maybe are creating a new cluster, handle that
|
||||||
if len(sense_or_example.translations) == new_cluster_idx:
|
if len(sense_or_example.translations) == new_cluster_idx:
|
||||||
sense_or_example.translations.append([self.translation])
|
sense_or_example.translations.append([self.translation])
|
||||||
@@ -66,12 +73,12 @@ class EditTranslation(DataChgClickMessage):
|
|||||||
sense_or_example.translations[new_cluster_idx].append(self.translation)
|
sense_or_example.translations[new_cluster_idx].append(self.translation)
|
||||||
else:
|
else:
|
||||||
raise ValueError("Bad new cluster idx :(")
|
raise ValueError("Bad new cluster idx :(")
|
||||||
|
|
||||||
# we still hold cluster reference, check if empty and remove if necessary
|
# we still hold cluster reference, check if empty and remove if necessary
|
||||||
# we cant do this earlier since indexes change and yeah, fun stuff
|
# we cant do this earlier since indexes change and yeah, fun stuff
|
||||||
if len(cluster) == 0:
|
if len(cluster) == 0:
|
||||||
sense_or_example.translations.splice(cidx, 1)
|
sense_or_example.translations.splice(cidx, 1)
|
||||||
|
|
||||||
|
|
||||||
class MoveRight(DataChgClickMessage):
|
class MoveRight(DataChgClickMessage):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
@@ -80,8 +87,8 @@ class MoveRight(DataChgClickMessage):
|
|||||||
if idx != len(cluster) - 1:
|
if idx != len(cluster) - 1:
|
||||||
cluster[idx], cluster[idx + 1] = cluster[idx + 1], cluster[idx]
|
cluster[idx], cluster[idx + 1] = cluster[idx + 1], cluster[idx]
|
||||||
model.translation = None
|
model.translation = None
|
||||||
|
|
||||||
|
|
||||||
class MoveLeft(DataChgClickMessage):
|
class MoveLeft(DataChgClickMessage):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
translation = self.get_arg(0, Translation)
|
translation = self.get_arg(0, Translation)
|
||||||
@@ -89,8 +96,8 @@ class MoveLeft(DataChgClickMessage):
|
|||||||
if idx != 0 and len(cluster) > 1:
|
if idx != 0 and len(cluster) > 1:
|
||||||
cluster[idx], cluster[idx - 1] = cluster[idx - 1], cluster[idx]
|
cluster[idx], cluster[idx - 1] = cluster[idx - 1], cluster[idx]
|
||||||
model.translation = None
|
model.translation = None
|
||||||
|
|
||||||
|
|
||||||
class BinTranslation(DataChgClickMessage):
|
class BinTranslation(DataChgClickMessage):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
translation = self.get_arg(0, Translation)
|
translation = self.get_arg(0, Translation)
|
||||||
@@ -101,7 +108,7 @@ class BinTranslation(DataChgClickMessage):
|
|||||||
else:
|
else:
|
||||||
cluster.splice(tidx, 1)
|
cluster.splice(tidx, 1)
|
||||||
model.translation = None
|
model.translation = None
|
||||||
|
|
||||||
|
|
||||||
class AddTranslation(EditTranslation):
|
class AddTranslation(EditTranslation):
|
||||||
def handle_cluster_change(self, new_cluster_idx, _):
|
def handle_cluster_change(self, new_cluster_idx, _):
|
||||||
@@ -110,4 +117,4 @@ class AddTranslation(EditTranslation):
|
|||||||
# we make a dummy cluster, cluster_idx and translation_idx
|
# we make a dummy cluster, cluster_idx and translation_idx
|
||||||
# we give a correct new_cluster_idx
|
# we give a correct new_cluster_idx
|
||||||
self.do_cluster_change(self.get_arg(2), [None, None], None, None, new_cluster_idx)
|
self.do_cluster_change(self.get_arg(2), [None, None], None, None, new_cluster_idx)
|
||||||
|
|
||||||
|
|||||||
@@ -2,3 +2,4 @@ from model.model import Model
|
|||||||
from model.sense import Sense
|
from model.sense import Sense
|
||||||
from model.translation import Translation
|
from model.translation import Translation
|
||||||
from model.example import Example
|
from model.example import Example
|
||||||
|
from model.explanation import Explanation
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ class Entry(Data):
|
|||||||
self.headword = ""
|
self.headword = ""
|
||||||
self.homonymy = []
|
self.homonymy = []
|
||||||
self.headword_type = None
|
self.headword_type = None
|
||||||
|
self.headword_audio = None
|
||||||
self.grammar = ""
|
self.grammar = ""
|
||||||
self.comment = ""
|
self.comment = ""
|
||||||
self.variants = []
|
self.variants = []
|
||||||
@@ -22,16 +23,20 @@ class Entry(Data):
|
|||||||
self.measure = {}
|
self.measure = {}
|
||||||
self.labels = []
|
self.labels = []
|
||||||
self.senses = []
|
self.senses = []
|
||||||
|
self.original_xml = None
|
||||||
|
|
||||||
def import_xml(self, entry_xml):
|
def import_xml(self, entry_xml):
|
||||||
|
self.original_xml = entry_xml.cloneNode(True)
|
||||||
status = entry_xml.querySelector("head status")
|
status = entry_xml.querySelector("head status")
|
||||||
|
|
||||||
headword = entry_xml.querySelector("head headword lemma")
|
headword = entry_xml.querySelector("head headword lemma")
|
||||||
|
|
||||||
grammar = entry_xml.querySelector("head grammar category")
|
grammar = entry_xml.querySelector("head grammar category")
|
||||||
comment = entry_xml.querySelector("head comment")
|
comment = entry_xml.querySelector("head comment")
|
||||||
self.status = status.textContent if status else ""
|
self.status = status.textContent if status else ""
|
||||||
self.headword = headword.textContent if headword else ""
|
self.headword = headword.textContent if headword else ""
|
||||||
self.headword_type = headword.getAttribute("type") if headword else None
|
self.headword_type = headword.getAttribute("type") if headword and headword.hasAttribute("type") else None
|
||||||
|
self.headword_audio = headword.getAttribute("audio") if headword and headword.hasAttribute("audio") else None
|
||||||
self.grammar = grammar.textContent if grammar else ""
|
self.grammar = grammar.textContent if grammar else ""
|
||||||
self.comment = comment.textContent if comment else ""
|
self.comment = comment.textContent if comment else ""
|
||||||
self.variants = [v.textContent for v in entry_xml.querySelectorAll("head variantList variant")]
|
self.variants = [v.textContent for v in entry_xml.querySelectorAll("head variantList variant")]
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class ComponentLexeme(Data):
|
|||||||
self.text = ""
|
self.text = ""
|
||||||
self.role = ""
|
self.role = ""
|
||||||
self.no_space = False
|
self.no_space = False
|
||||||
|
|
||||||
def import_xml(self, xml):
|
def import_xml(self, xml):
|
||||||
if xml.nodeName == "#text":
|
if xml.nodeName == "#text":
|
||||||
self.text = xml.data
|
self.text = xml.data
|
||||||
@@ -19,33 +19,31 @@ class ComponentLexeme(Data):
|
|||||||
else:
|
else:
|
||||||
self.text = xml.textContent
|
self.text = xml.textContent
|
||||||
self.role = xml.getAttribute("role")
|
self.role = xml.getAttribute("role")
|
||||||
|
|
||||||
if xml.hasAttribute("space"):
|
if xml.hasAttribute("space"):
|
||||||
self.no_space = xml.getAttribute("space") == "false"
|
self.no_space = xml.getAttribute("space") == "false"
|
||||||
|
|
||||||
for oth_attr in ["lexical_unit_lexeme_id", "slolex", "kol"]:
|
for oth_attr in ["lexeme_id", "lexical_unit_lexeme_id", "slolex", "kol", "sloleks"]:
|
||||||
if xml.hasAttribute(oth_attr):
|
if xml.hasAttribute(oth_attr):
|
||||||
self.other_attributes[oth_attr] = xml.getAttribute(oth_attr)
|
self.other_attributes[oth_attr] = xml.getAttribute(oth_attr)
|
||||||
|
|
||||||
def isValid(self):
|
def isValid(self):
|
||||||
return len(self.text) > 0
|
return len(self.text) > 0
|
||||||
|
|
||||||
def export(self, doc):
|
def export(self, doc):
|
||||||
if self.role is None:
|
if self.role is None:
|
||||||
return doc.createTextNode(self.text)
|
return doc.createTextNode(self.text)
|
||||||
|
|
||||||
result = doc.createElement("comp")
|
result = doc.createElement("comp")
|
||||||
result.setAttribute("role", self.role)
|
result.setAttribute("role", self.role)
|
||||||
result.textContent = self.text
|
result.textContent = self.text
|
||||||
|
|
||||||
if self.no_space and self.no_space != self.LAST_COMPONENT_SPACE:
|
if self.no_space and self.no_space != self.LAST_COMPONENT_SPACE:
|
||||||
result.setAttribute("space", "false")
|
result.setAttribute("space", "false")
|
||||||
|
|
||||||
for key, value in self.other_attributes.items():
|
for key, value in self.other_attributes.items():
|
||||||
result.setAttribute(key, value)
|
result.setAttribute(key, value)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def view_style(self):
|
def view_style(self):
|
||||||
# no-space is handled in multiword-example directly
|
# no-space is handled in multiword-example directly
|
||||||
result = ".comp-text"
|
result = ".comp-text"
|
||||||
@@ -53,8 +51,8 @@ class ComponentLexeme(Data):
|
|||||||
result += ".comp-role"
|
result += ".comp-role"
|
||||||
if self.role == "headword":
|
if self.role == "headword":
|
||||||
result += ".comp-role-headword"
|
result += ".comp-role-headword"
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,12 +18,12 @@ class Example(Data):
|
|||||||
self.components = []
|
self.components = []
|
||||||
self.edited = False
|
self.edited = False
|
||||||
self.newly_created = False
|
self.newly_created = False
|
||||||
|
|
||||||
# removes space from last component if multiword example
|
# removes space from last component if multiword example
|
||||||
def check_multiword_components(self):
|
def check_multiword_components(self):
|
||||||
if self.is_multiword():
|
if self.is_multiword():
|
||||||
self.components[len(self.components) - 1].no_space = ComponentLexeme.LAST_COMPONENT_SPACE
|
self.components[len(self.components) - 1].no_space = ComponentLexeme.LAST_COMPONENT_SPACE
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def new_multiword():
|
def new_multiword():
|
||||||
example = Example()
|
example = Example()
|
||||||
@@ -32,105 +32,105 @@ class Example(Data):
|
|||||||
example.inner = MultiwordExample()
|
example.inner = MultiwordExample()
|
||||||
example.inner.cluster = ExampleClusters.first_empty_cluster()
|
example.inner.cluster = ExampleClusters.first_empty_cluster()
|
||||||
example.inner.type = "grammaticalCombination"
|
example.inner.type = "grammaticalCombination"
|
||||||
|
|
||||||
empty_component = ComponentLexeme()
|
empty_component = ComponentLexeme()
|
||||||
empty_component.role = "headword"
|
empty_component.role = "headword"
|
||||||
example.components.append(empty_component)
|
example.components.append(empty_component)
|
||||||
|
|
||||||
return example
|
return example
|
||||||
|
|
||||||
def import_xml(self, example_xml):
|
def import_xml(self, example_xml):
|
||||||
self.translations = from_container_list(example_xml.querySelectorAll("translationContainer"))
|
self.translations = from_container_list(example_xml.querySelectorAll("translationContainerList translationContainer"))
|
||||||
|
|
||||||
if example_xml.hasAttribute("modified"):
|
if example_xml.hasAttribute("modified"):
|
||||||
self.edited = example_xml.getAttribute("modified") == "true"
|
self.edited = example_xml.getAttribute("modified") == "true"
|
||||||
|
|
||||||
inner_xml = example_xml.querySelector("corpusExample")
|
inner_xml = example_xml.querySelector("corpusExample")
|
||||||
if inner_xml is not None:
|
if inner_xml is not None:
|
||||||
self.inner = CorpusExample()
|
self.inner = CorpusExample()
|
||||||
else:
|
else:
|
||||||
inner_xml = example_xml.querySelector("multiwordExample")
|
inner_xml = example_xml.querySelector("multiwordExample")
|
||||||
self.inner = MultiwordExample()
|
self.inner = MultiwordExample()
|
||||||
|
|
||||||
self.inner.import_xml(inner_xml)
|
self.inner.import_xml(inner_xml)
|
||||||
|
|
||||||
for idx, comp_xml in enumerate(inner_xml.childNodes):
|
for idx, comp_xml in enumerate(inner_xml.childNodes):
|
||||||
comp = ComponentLexeme()
|
comp = ComponentLexeme()
|
||||||
comp.import_xml(comp_xml)
|
comp.import_xml(comp_xml)
|
||||||
if comp.isValid():
|
if comp.isValid():
|
||||||
self.components.append(comp)
|
self.components.append(comp)
|
||||||
|
|
||||||
self.check_multiword_components()
|
self.check_multiword_components()
|
||||||
|
|
||||||
def export(self, doc):
|
def export(self, doc):
|
||||||
self.check_multiword_components()
|
self.check_multiword_components()
|
||||||
|
|
||||||
result = doc.createElement("exampleContainer")
|
result = doc.createElement("exampleContainer")
|
||||||
|
|
||||||
inner = self.inner.export(doc, self.edited)
|
inner = self.inner.export(doc, self.edited)
|
||||||
# TODO: bad quick fix
|
# TODO: bad quick fix
|
||||||
for comp in self.components:
|
for comp in self.components:
|
||||||
inner.appendChild(comp.export(doc))
|
inner.appendChild(comp.export(doc))
|
||||||
|
|
||||||
result.appendChild(inner)
|
result.appendChild(inner)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def view(self, model, sense):
|
def view(self, model, sense):
|
||||||
example_tag = "div.example-rest"
|
example_tag = "div.example-rest"
|
||||||
if self in model.chosen_examples:
|
if self in model.chosen_examples:
|
||||||
example_tag += ".example-chosen"
|
example_tag += ".example-chosen"
|
||||||
|
|
||||||
cluster = self.get_cluster()
|
cluster = self.get_cluster()
|
||||||
dot_attr = {"style": { "visibility": "visible" if cluster is None else "hidden"}}
|
dot_attr = {"style": { "visibility": "visible" if cluster is None else "hidden"}}
|
||||||
|
|
||||||
example_content = []
|
example_content = []
|
||||||
if cluster is not None:
|
if cluster is not None:
|
||||||
example_content.append(h("span.example-cluster", {}, str(cluster + 1)))
|
example_content.append(h("span.example-cluster", {}, str(cluster + 1)))
|
||||||
|
|
||||||
example_text_inner_tag = "span.example-text-{}".format(self.get_view_type())
|
example_text_inner_tag = "span.example-text-{}".format(self.get_view_type())
|
||||||
example_content.append(h(example_text_inner_tag, {}, self.inner.view(self.components)))
|
example_content.append(h(example_text_inner_tag, {}, self.inner.view(self.components)))
|
||||||
|
|
||||||
other_attributes = self.get_other_attributes()
|
other_attributes = self.get_other_attributes()
|
||||||
if "frequency" in other_attributes:
|
if "frequency" in other_attributes:
|
||||||
example_content.append(h("span.example-frequency", {}, other_attributes["frequency"]))
|
example_content.append(h("span.example-frequency", {}, other_attributes["frequency"]))
|
||||||
if "logDice" in other_attributes:
|
if "logDice" in other_attributes:
|
||||||
example_content.append(h("span.example-logdice", {}, other_attributes["logDice"]))
|
example_content.append(h("span.example-logdice", {}, other_attributes["logDice"]))
|
||||||
|
|
||||||
parent_display = "none"
|
parent_display = "none"
|
||||||
if model.examples_shown or self.is_multiword() or len(self.translations) > 0:
|
if model.examples_shown or self.is_multiword() or len(self.translations) > 0:
|
||||||
parent_display = "inherit"
|
parent_display = "inherit"
|
||||||
|
|
||||||
clusters_display = "inherit"
|
clusters_display = "inherit"
|
||||||
if not model.clusters_shown:
|
if not model.clusters_shown:
|
||||||
clusters_display = "none"
|
clusters_display = "none"
|
||||||
|
|
||||||
return h("div.example", {"style": {"display": parent_display}}, [
|
return h("div.example", {"style": {"display": parent_display}}, [
|
||||||
h("div.example-dot", dot_attr, "▣"),
|
h("div.example-dot", dot_attr, "▣"),
|
||||||
h(example_tag, {}, [
|
h(example_tag, {}, [
|
||||||
h("span.example-text", {"on": {"click": M.msg(M.ShowExampleMenu, self)} }, example_content),
|
h("span.example-text", {"on": {"click": M.msg(M.ShowExampleMenu, self)} }, example_content),
|
||||||
h("div.example-translation-list", {}, [
|
h("div.example-translation-list", {}, [
|
||||||
h("div.example-translation", {}, View.view_translations(self.translations, self, model))]),
|
h("div.example-translation", {}, View.view_translations(self.translations, self, model))]),
|
||||||
h("div.example-clusters",
|
h("div.example-clusters",
|
||||||
{"style": {"display": clusters_display }}, show_toggle_cluster_buttons(sense, self))])])
|
{"style": {"display": clusters_display }}, show_toggle_cluster_buttons(sense, self))])])
|
||||||
|
|
||||||
def simple_view(self):
|
def simple_view(self):
|
||||||
return self.inner.view(self.components)
|
return self.inner.view(self.components)
|
||||||
|
|
||||||
def get_cluster(self):
|
def get_cluster(self):
|
||||||
return self.inner.get_cluster()
|
return self.inner.get_cluster()
|
||||||
|
|
||||||
def set_cluster(self, cluster):
|
def set_cluster(self, cluster):
|
||||||
self.inner.cluster = cluster
|
self.inner.cluster = cluster
|
||||||
|
|
||||||
def get_structure(self):
|
def get_structure(self):
|
||||||
return self.inner.get_structure()
|
return self.inner.get_structure()
|
||||||
|
|
||||||
def is_collocation(self):
|
def is_collocation(self):
|
||||||
return self.get_view_type() == 2
|
return self.get_view_type() == 2
|
||||||
|
|
||||||
def is_multiword(self):
|
def is_multiword(self):
|
||||||
return self.get_view_type() != 1
|
return self.get_view_type() != 1
|
||||||
|
|
||||||
def get_view_type(self):
|
def get_view_type(self):
|
||||||
# as per the bosses, these are the rules for different colors
|
# as per the bosses, these are the rules for different colors
|
||||||
if type(self.inner) is CorpusExample:
|
if type(self.inner) is CorpusExample:
|
||||||
@@ -139,8 +139,8 @@ class Example(Data):
|
|||||||
return 2
|
return 2
|
||||||
else:
|
else:
|
||||||
return 3
|
return 3
|
||||||
|
|
||||||
def get_other_attributes(self):
|
def get_other_attributes(self):
|
||||||
return self.inner.other_attributes
|
return self.inner.other_attributes
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
21
src/model/explanation.py
Normal file
21
src/model/explanation.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
from model.data import Data
|
||||||
|
|
||||||
|
from lib.snabbdom import h
|
||||||
|
|
||||||
|
|
||||||
|
class Explanation(Data):
|
||||||
|
def __init__(self):
|
||||||
|
self.value = ""
|
||||||
|
self.language = ""
|
||||||
|
|
||||||
|
def import_dom(self, explanation_dom):
|
||||||
|
|
||||||
|
self.value = explanation_dom.textContent if explanation_dom else ""
|
||||||
|
self.language = explanation_dom.getAttribute("language") if explanation_dom.hasAttribute("language") else ""
|
||||||
|
|
||||||
|
def export(self, doc):
|
||||||
|
result = doc.createElement("explanation")
|
||||||
|
result.textContent = self.value
|
||||||
|
if self.language != "": result.setAttribute('language', self.language)
|
||||||
|
|
||||||
|
return result
|
||||||
@@ -15,37 +15,37 @@ class Sense(Data):
|
|||||||
self.labels = []
|
self.labels = []
|
||||||
self.translations = []
|
self.translations = []
|
||||||
self.examples = []
|
self.examples = []
|
||||||
|
|
||||||
def import_xml(self, sense_xml, idx):
|
def import_xml(self, sense_xml, idx):
|
||||||
self.original_idx = idx
|
self.original_idx = idx
|
||||||
|
|
||||||
for definition in sense_xml.querySelectorAll("definitionList definition"):
|
for definition in sense_xml.querySelectorAll("definitionList definition"):
|
||||||
key = definition.getAttribute("type")
|
key = definition.getAttribute("type")
|
||||||
self.definition[key] = definition.textContent
|
self.definition[key] = definition.textContent
|
||||||
|
|
||||||
self.labels = import_label_list("sense > labelList label", sense_xml)
|
self.labels = import_label_list("sense > labelList label", sense_xml)
|
||||||
self.translations = from_container_list(
|
self.translations = from_container_list(
|
||||||
sense_xml.querySelectorAll("translationContainerList translationContainer"))
|
sense_xml.querySelectorAll('sense > translationContainerList translationContainer'))
|
||||||
|
|
||||||
for example_xml in sense_xml.querySelectorAll("exampleContainerList exampleContainer"):
|
for example_xml in sense_xml.querySelectorAll("exampleContainerList exampleContainer"):
|
||||||
example = Example()
|
example = Example()
|
||||||
example.import_xml(example_xml)
|
example.import_xml(example_xml)
|
||||||
self.examples.append(example)
|
self.examples.append(example)
|
||||||
|
|
||||||
|
|
||||||
def merge_labels(self):
|
def merge_labels(self):
|
||||||
return ", ".join(val for _, val in self.labels)
|
return ", ".join(val for _, val in self.labels)
|
||||||
|
|
||||||
|
|
||||||
def view(self, model, sense_num):
|
def view(self, model, sense_num):
|
||||||
examples = [example.view(model, self) for example in self.examples]
|
examples = [example.view(model, self) for example in self.examples]
|
||||||
|
|
||||||
result = h("div.elm-div", {}, [
|
result = h("div.elm-div", {}, [
|
||||||
h("div.sense-num", {"on": {"click": M.msg(M.ShowSenseMenu, self)}}, str(sense_num + 1)),
|
h("div.sense-num", {"on": {"click": M.msg(M.ShowSenseMenu, self)}}, str(sense_num + 1)),
|
||||||
h("div.sense", {}, [
|
h("div.sense", {}, [
|
||||||
h("span.sense-label-list", { "on": { "click": M.msg(M.ShowSenseLabelEdit, self) }}, [
|
h("span.sense-label-list", { "on": { "click": M.msg(M.ShowSenseLabelEdit, self) }}, [
|
||||||
h("span.sense-label", {}, clean_label(slabel)) for _, slabel in self.labels ]),
|
h("span.sense-label", {}, clean_label(slabel)) for _, slabel in self.labels ]),
|
||||||
h("span.sense-definition", { "on": { "click": M.msg(M.ShowSenseDefinitionEdit, self) }}, self.definition["indicator"]),
|
h("span.sense-definition", { "on": { "click": M.msg(M.ShowSenseDefinitionEdit, self) }}, self.definition["indicator"]),
|
||||||
h("div", {}, View.view_translations(self.translations, self, model)),
|
h("div", {}, View.view_translations(self.translations, self, model)),
|
||||||
h("div", {}, examples)])])
|
h("div", {}, examples)])])
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from model.tags import import_label_list
|
from model.tags import import_label_list
|
||||||
|
from model.explanation import Explanation
|
||||||
from model.data import Data
|
from model.data import Data
|
||||||
|
|
||||||
from lib.snabbdom import h
|
from lib.snabbdom import h
|
||||||
@@ -9,21 +10,21 @@ import message as M
|
|||||||
def from_container_list(translation_list_container_xml):
|
def from_container_list(translation_list_container_xml):
|
||||||
translations = []
|
translations = []
|
||||||
max_num_cluster = 0
|
max_num_cluster = 0
|
||||||
|
|
||||||
for translation_xml in translation_list_container_xml:
|
for translation_xml in translation_list_container_xml:
|
||||||
num_cluster = 1 # default cluster
|
num_cluster = 1 # default cluster
|
||||||
if translation_xml.hasAttribute("cluster"):
|
if translation_xml.hasAttribute("cluster"):
|
||||||
num_cluster = int(translation_xml.getAttribute("cluster"))
|
num_cluster = int(translation_xml.getAttribute("cluster"))
|
||||||
|
|
||||||
max_num_cluster = max(max_num_cluster, num_cluster)
|
max_num_cluster = max(max_num_cluster, num_cluster)
|
||||||
t = Translation()
|
t = Translation()
|
||||||
t.import_xml(translation_xml)
|
t.import_xml(translation_xml)
|
||||||
translations.append((num_cluster, t))
|
translations.append((num_cluster, t))
|
||||||
|
|
||||||
result = [[] for _ in range(max_num_cluster)]
|
result = [[] for _ in range(max_num_cluster)]
|
||||||
for clusterNum, translation in translations:
|
for clusterNum, translation in translations:
|
||||||
result[clusterNum - 1].append(translation)
|
result[clusterNum - 1].append(translation)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@@ -32,47 +33,54 @@ class Translation(Data):
|
|||||||
self.translation = ""
|
self.translation = ""
|
||||||
self.source = ""
|
self.source = ""
|
||||||
self.targetLang = ""
|
self.targetLang = ""
|
||||||
self.explanation = ""
|
self.audio = ""
|
||||||
|
self.explanationList = set()
|
||||||
self.tags = []
|
self.tags = []
|
||||||
|
|
||||||
def import_xml(self, translation_xml):
|
def import_xml(self, translation_xml):
|
||||||
translation = translation_xml.querySelector("translation")
|
translation = translation_xml.querySelector("translation")
|
||||||
|
|
||||||
if translation:
|
if translation:
|
||||||
self.translation = translation.textContent
|
self.translation = translation.textContent
|
||||||
self.source = translation.getAttribute("source") if translation.hasAttribute("source") else ""
|
self.source = translation.getAttribute("source") if translation.hasAttribute("source") else ""
|
||||||
self.targetLang = translation.getAttribute("targetLang") if translation.hasAttribute("targetLang") else ""
|
self.targetLang = translation.getAttribute("targetLang") if translation.hasAttribute("targetLang") else ""
|
||||||
|
self.audio = translation.getAttribute("audio") if translation.hasAttribute("audio") else ""
|
||||||
explanation = translation_xml.querySelector("explanation")
|
|
||||||
self.explanation = explanation.textContent if explanation else ""
|
explanationList = translation_xml.querySelectorAll("explanationList explanation")
|
||||||
|
for explanation_dom in explanationList:
|
||||||
|
explanation = Explanation()
|
||||||
|
explanation.import_dom(explanation_dom)
|
||||||
|
self.explanationList.append(explanation)
|
||||||
|
|
||||||
self.tags = import_label_list("labelList label", translation_xml)
|
self.tags = import_label_list("labelList label", translation_xml)
|
||||||
|
|
||||||
|
|
||||||
def view(self, model):
|
def view(self, model):
|
||||||
elements = []
|
elements = []
|
||||||
|
|
||||||
if self.tags:
|
if self.tags:
|
||||||
tags = h("div.translation-tags", {}, [
|
tags = h("div.translation-tags", {}, [
|
||||||
h("span", {"attr": {"title": key}}, clean_label(value))
|
h("span", {"attr": {"title": key}}, clean_label(value))
|
||||||
for key, value in self.tags])
|
for key, value in self.tags])
|
||||||
elements.append(tags)
|
elements.append(tags)
|
||||||
|
|
||||||
elements.append(h("span.translation-text", {}, self.translation))
|
elements.append(h("span.translation-text", {}, self.translation))
|
||||||
if self.source:
|
if self.source:
|
||||||
elements.append(h("span.translation-source", {}, self.source))
|
elements.append(h("span.translation-source", {}, self.source))
|
||||||
|
|
||||||
explanation_class = ".translation-explanation" if self.translation else ""
|
if (self.explanationList):
|
||||||
elements.append(h("span{}".format(explanation_class), {}, self.explanation))
|
explanation_class = ".explanations" if self.translation else ".explanations.solo"
|
||||||
|
explanations = [explanation.value for explanation in self.explanationList]
|
||||||
|
elements.append(h("span{}".format(explanation_class), {}, ", ".join(explanations)))
|
||||||
|
|
||||||
return h("div.translation-div", {"on": {"click": M.msg(M.ShowTranslationMenu, self) }}, elements)
|
return h("div.translation-div", {"on": {"click": M.msg(M.ShowTranslationMenu, self) }}, elements)
|
||||||
|
|
||||||
|
|
||||||
def is_empty(self):
|
def is_empty(self):
|
||||||
result = True
|
result = True
|
||||||
result = result and self.translation == ""
|
result = result and self.translation == ""
|
||||||
# next two are not checked as the also can not be deleted via gui
|
# next two are not checked as the also can not be deleted via gui
|
||||||
# result = result and self.source == ""
|
# result = result and self.source == ""
|
||||||
# result = result and self.targetLang == ""
|
# result = result and self.targetLang == ""
|
||||||
result = result and self.explanation == ""
|
result = result and len(self.explanationList) == 0
|
||||||
result = result and len(self.tags) == 0
|
result = result and len(self.tags) == 0
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ def generic_list_editor(title, element_list_getter):
|
|||||||
|
|
||||||
def homonymy_editor(title, current_labels):
|
def homonymy_editor(title, current_labels):
|
||||||
def split_line2(left, right):
|
def split_line2(left, right):
|
||||||
cls = "flex.two{}".format(".label-list-row")
|
cls = "flex.two{}".format(".double-list-row")
|
||||||
return h("div.{}".format(cls), {}, [
|
return h("div.{}".format(cls), {}, [
|
||||||
h("div.half", {}, left), h("div.half", {}, right)])
|
h("div.half", {}, left), h("div.half", {}, right)])
|
||||||
|
|
||||||
@@ -67,6 +67,28 @@ def homonymy_editor(title, current_labels):
|
|||||||
|
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
def explanation_editor(title, current_labels):
|
||||||
|
def split_line2(left, right):
|
||||||
|
cls = "flex.two{}".format(".double-list-row")
|
||||||
|
return h("div.{}".format(cls), {}, [
|
||||||
|
h("div.four-fifth", {}, left), h("div.fifth", {}, right)])
|
||||||
|
|
||||||
|
content = [h("p", {}, title)]
|
||||||
|
for i, explanation in enumerate(current_labels()):
|
||||||
|
language = []
|
||||||
|
value = []
|
||||||
|
language.append(h("label", {"attrs": {"for": i}}, "Language:"))
|
||||||
|
language.append(h("input.language-input", {"props": {"type": "text", "value": explanation["language"], "id": i}}, ""))
|
||||||
|
value.append(h("label", {"attrs": {"for": i + "-value"}}, "Value:"))
|
||||||
|
value.append(h("input.value-input", {"props": {"type": "text", "value": explanation["value"], "id": i + "-value"}}, ""))
|
||||||
|
|
||||||
|
content.append(split_line2(value, language))
|
||||||
|
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, current_labels)}}, "+"))
|
||||||
|
|
||||||
|
return content
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def label_list_editor(current_labels, add_label_message_class):
|
def label_list_editor(current_labels, add_label_message_class):
|
||||||
def split_line3(left, center, right, is_llr=True):
|
def split_line3(left, center, right, is_llr=True):
|
||||||
cls = "flex.three{}".format(".label-list-row" if is_llr else "")
|
cls = "flex.three{}".format(".label-list-row" if is_llr else "")
|
||||||
|
|||||||
@@ -19,10 +19,9 @@ def edit_translation(translation, parent, cluster_idx, num_clusters, cls):
|
|||||||
|
|
||||||
# first line: transalation itself
|
# first line: transalation itself
|
||||||
content.extend([
|
content.extend([
|
||||||
split_line2("Prevedek:",
|
split_line2("Prevedek:", h("textarea#etv", {"props": {"value": translation.translation}}, ""))])
|
||||||
h("textarea#etv", {"props": {"value": translation.translation}}, "")),
|
|
||||||
split_line2("Razlaga:",
|
content.extend(explanation_editor("Razlage:", lambda: translation.explanationList))
|
||||||
h("textarea#ete", {"props": {"value": translation.explanation}}, ""))])
|
|
||||||
|
|
||||||
# cluster number
|
# cluster number
|
||||||
options = [h("option", {"props": {"selected": idx == cluster_idx}}, str(idx + 1)) for idx in range(num_clusters + 1)]
|
options = [h("option", {"props": {"selected": idx == cluster_idx}}, str(idx + 1)) for idx in range(num_clusters + 1)]
|
||||||
|
|||||||
Reference in New Issue
Block a user