Compare commits

..

No commits in common. "master" and "mt-initial-setup" have entirely different histories.

26 changed files with 356 additions and 628 deletions

2
.gitignore vendored
View File

@ -10,5 +10,5 @@ build/*
# using kdev4, works fairly nicely! # using kdev4, works fairly nicely!
.kdev4 .kdev4
**/*.kdev4 **/*.kdev4
remote

View File

@ -1,3 +1,5 @@
.PHONY: all release build transcrypt copy $(RES_LESS_FILE) $(RES_PY_FILE) $(RES_HTML_FILE) $(RES_XML_FILE)
SRC_FOLDER=$(CURDIR)/../src SRC_FOLDER=$(CURDIR)/../src
RES_FOLDER=$(CURDIR)/../res RES_FOLDER=$(CURDIR)/../res
@ -18,7 +20,6 @@ RES_PY_FILE=$(SRC_FOLDER)/$(PY_FILE)
RES_HTML_FILE=$(RES_FOLDER)/$(HTML_FILE) RES_HTML_FILE=$(RES_FOLDER)/$(HTML_FILE)
RES_XML_FILE=$(RES_FOLDER)/$(XML_FILE) RES_XML_FILE=$(RES_FOLDER)/$(XML_FILE)
.PHONY: all release build transcrypt copy $(RES_LESS_FILE) $(RES_PY_FILE) $(RES_HTML_FILE) $(RES_XML_FILE) $(CONV_FILE)
.DEFAULT_GOAL := all .DEFAULT_GOAL := all
all: BR_FLAGS := $(BR_FLAGS) --debug all: BR_FLAGS := $(BR_FLAGS) --debug

View File

@ -24,4 +24,4 @@ tar czf - ./config.json ./bundle.js ./local.js ./main.css ./main.html | ssh $USE
# Create a simlink on VPS that will enable specific plugin on https://lexonomy.cjvt.si/ # Create a simlink on VPS that will enable specific plugin on https://lexonomy.cjvt.si/
# Routes must be absolute or it doesn't work. # Routes must be absolute or it doesn't work.
ssh -t $USERNAME -p $VPS_PASSWORD "sudo -s unlink /home/ozbolt/plugins/$PLUGIN_NAME || true && sudo ln -s /home/$VPS_USERNAME/plugins/$PLUGIN_NAME /home/ozbolt/plugins/$PLUGIN_NAME" ssh -t $USERNAME -p $VPS_PASSWORD "sudo ln -s /home/$VPS_USERNAME/plugins/$PLUGIN_NAME /home/ozbolt/plugins/$PLUGIN_NAME"

View File

@ -3,20 +3,16 @@
# fail if any command fails # fail if any command fails
set -e set -e
OUT_FILE=conversions.csv
if [[ -z "${API_KEY}" ]]; then if [[ -z "${API_KEY}" ]]; then
echo "API_KEY not defined, should be api key to CJVT's gitea" echo "API_KEY not defined, should be api key to CJVT's gitea"
exit 1 exit 1
fi fi
if [ -f $OUT_FILE ]; then OUT_FILE=conversions.csv
echo "file for conversion of SKE collocations: '$OUT_FILE' already exists, skipping."
exit 0
fi
TEMP_FILE=$(mktemp) TEMP_FILE=$(mktemp)
rm -r $OUT_FILE
curl -s "https://gitea.cjvt.si/api/v1/repos/generic/data_admin/contents/resources/structure_conversions.csv?token=$API_KEY" -o $TEMP_FILE curl -s "https://gitea.cjvt.si/api/v1/repos/generic/data_admin/contents/resources/structure_conversions.csv?token=$API_KEY" -o $TEMP_FILE
echo "wc: $(wc $TEMP_FILE)" echo "wc: $(wc $TEMP_FILE)"
cat $TEMP_FILE | python3 -c "import sys, json; print(json.load(sys.stdin)['content'])" | base64 -d > $OUT_FILE cat $TEMP_FILE | python3 -c "import sys, json; print(json.load(sys.stdin)['content'])" | base64 -d > $OUT_FILE

View File

@ -156,7 +156,16 @@
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 {
@ -166,20 +175,6 @@
} }
} }
.explanations:not(:empty) {
font-style: italic;
&:not(.solo) {
&:before {
content: '[';
}
&:after {
content: ']';
}
}
}
.example { .example {
clear: left; clear: left;
margin-left: 1em; margin-left: 1em;

View File

@ -4,12 +4,7 @@
<head> <head>
<status>LBS</status> <status>LBS</status>
<headword> <headword>
<lemma>aplikativen3</lemma> <lemma>aplikativen</lemma>
<homonymy>
<homonymyFeature name="pronunciation">bolníšnica</homonymyFeature>
<homonymyFeature name="blahblah">xyz</homonymyFeature>
<homonymyFeature name="bluhbluh">abc</homonymyFeature>
</homonymy>
</headword> </headword>
<grammar> <grammar>
<category>pridevnik</category> <category>pridevnik</category>

View File

@ -5,12 +5,13 @@ 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):
parser = __new__(DOMParser()) parser = __new__(DOMParser())
doc = parser.parseFromString("<entry />", "text/xml") doc = parser.parseFromString("<entry />", "text/xml")
entry_xml = doc.firstChild entry_xml = doc.firstChild
# create head # create head
@ -23,28 +24,12 @@ 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)
homonymy = doc.createElement("homonymy")
headword.appendChild(homonymy)
for hFeature in entry.homonymy:
feature = doc.createElement("homonymyFeature")
feature.textContent = hFeature.value
# Can't use hFeature.name, because Python has name reserver and so it becomes py_name in JS
feature.setAttribute("name", hFeature["name"])
homonymy.appendChild(feature)
# if({}) works uncorrectly in transcrypt # if({}) works uncorrectly in transcrypt
if len(entry.lexical_unit) > 0: if len(entry.lexical_unit) > 0:
lexunit = doc.createElement("lexicalUnit") lexunit = doc.createElement("lexicalUnit")
@ -57,14 +42,12 @@ def export_entry(entry):
lexunit.appendChild(lexeme) lexunit.appendChild(lexeme)
head.appendChild(lexunit) head.appendChild(lexunit)
grammar = doc.createElement("grammar") grammar = doc.createElement("grammar")
grammar_category = doc.createElement("category") grammar_category = doc.createElement("category")
grammar_category.textContent = entry.grammar grammar_category.textContent = entry.grammar
grammar.appendChild(grammar_category) grammar.appendChild(grammar_category)
head.appendChild(grammar) head.appendChild(grammar)
if len(entry.measure) > 0: if len(entry.measure) > 0:
measure_list = doc.createElement("measureList") measure_list = doc.createElement("measureList")
measure = doc.createElement("measure") measure = doc.createElement("measure")
@ -132,9 +115,7 @@ 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)
translation_container_list = doc.createElement("translationContainerList") export_translation_list(doc, example, example_container)
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
@ -155,27 +136,16 @@ 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)
if len(translation.explanationList) > 0 : explanation = doc.createElement("explanation")
explanationList = _export_explanation_list(doc, translation.explanationList) explanation.textContent = translation.explanation
translation_xml.appendChild(explanationList) translation_xml.appendChild(explanation)
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")

View File

@ -24,41 +24,29 @@ def build_structure_conversions():
if line[1] == "struktura": if line[1] == "struktura":
continue continue
vto_structure = line[1].strip().split(">")[1].split("<")[0]
vto_name = line[2].strip() vto_name = line[2].strip()
vto_id = line[6].strip() vto_id = line[4].strip()
if 0 in (len(vto_name), len(vto_id)): if 0 in (len(vto_name), len(vto_id)):
continue continue
vfrom = "^" + line[0].replace("?", "\?").replace("%s", "([a-zA-Z螚ȎŠ-]+)") + "$" vfrom = "^" + line[0].replace("?", "\?").replace("%s", "([a-zA-Z螚ȎŠ-]+)") + "$"
structure_conversions.append((__new__(RegExp(vfrom, 'u')), vto_name, vto_structure, vto_id)) structure_conversions.append((__new__(RegExp(vfrom, 'u')), vto_name, vto_id))
def convert_structure(structure, type): def convert_structure(structure):
if structure_conversions is None: if structure_conversions is None:
build_structure_conversions() build_structure_conversions()
for vfrom, vto_name, vto_structure, 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 106, 107, 44 which instead matched with 30
if match and vto_id == '30' and '-s' in type:
vto_name = 's0-vp-s0'
vto_id = '106'
elif match and vto_id == '30' and '-g' in type:
vto_name = 'gg-vp-gg'
vto_id = '107'
elif match and vto_id == '30' and '-r' in type:
vto_name = 'r-vp-r'
vto_id = '44'
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_structure, vto_id return result, vto_id
window.console.log("Unknown structure: ", structure) window.console.log("Unknown structure: ", structure)
return 'N/A', '/' return None

View File

@ -1,11 +1,11 @@
from message.simple_messages import NoReset, Reset, ModalNotOkClose, ClickMessage, DataChgClickMessage, KeyboardPress, NoAction from message.simple_messages import NoReset, Reset, ModalNotOkClose, ClickMessage, DataChgClickMessage, KeyboardPress, NoAction
from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation
from message.show_messages import ShowEntryLabelsEdit, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowExampleEdit, ShowVariantsEdit, ShowHomonymyEdit, ShowRelatedEntriesEdit from message.show_messages import ShowEntryLabelsEdit, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowExampleEdit, ShowVariantsEdit, ShowRelatedEntriesEdit
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, AddExampleTranslation, DoChosenExamples, AddToLabelList, AddToGenericList, EditVariants, EditHomonymy, EditRelatedEntries, EditEntryLabels, ExampleClusterEdit, ExampleClusterAdd from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, AddExampleTranslation, DoChosenExamples, AddToLabelList, AddToGenericList, EditVariants, EditRelatedEntries, EditEntryLabels, ExampleClusterEdit, ExampleClusterAdd
from message.show_menu import ShowTranslationMenu, ShowSenseMenu, ShowExampleMenu from message.show_menu import ShowTranslationMenu, ShowSenseMenu, ShowExampleMenu
from message.sense_edit import SenseMoveUp, SenseMoveDown, SenseBin, AddMultiwordExample from message.sense_edit import SenseMoveUp, SenseMoveDown, SenseBin, AddMultiwordExample
from message.example_edit import ExampleMoveUp, ExampleMoveDown, ExampleBin, ExampleRoleChange, ExampleComponentSpace, ExampleComponentAdd, ExampleComponentRemove, EditExampleText, ToggleExamples, ToggleClusters from message.example_edit import ExampleMoveUp, ExampleMoveDown, ExampleBin, ExampleRoleChange, ExampleComponentSpace, ExampleComponentAdd, ExampleComponentRemove, EditExampleText, ToggleExamples, ToggleClusters
from message.delete_messages import DeleteComment, DeleteVariants, DeleteHomonymy, DeleteRelatedEntries, DeleteEntryLabels from message.delete_messages import DeleteComment, DeleteVariants, DeleteRelatedEntries, DeleteEntryLabels
from message.ske_messages import ShowSkeModal, SearchInSkeModal, SkeInsert from message.ske_messages import ShowSkeModal, SearchInSkeModal, SkeInsert
from message.message import msg, delayed_msg from message.message import msg, delayed_msg

View File

@ -9,24 +9,6 @@ def generic_list_getter():
result.append(result_candidate) result.append(result_candidate)
return result return result
# Formats data from inputs to name-value objects
def double_list_getter(firstParameter, secondParameter, allowEmptyField = False):
result = []
for row in document.getElementsByClassName("double-list-row"):
firstValue = row.querySelector("." + firstParameter + "-input").value
secondValue = row.querySelector("." + secondParameter + "-input").value
if (allowEmptyField is False and '' in [firstValue, secondValue]):
continue
if (allowEmptyField is True and all('' == value or value.isspace() for value in [firstValue, secondValue])):
continue
result.append({firstParameter: firstValue, secondParameter: secondValue})
return result
def label_list_getter(): def label_list_getter():
result = [] result = []
for row in document.getElementsByClassName("label-list-row"): for row in document.getElementsByClassName("label-list-row"):

View File

@ -18,14 +18,6 @@ class DeleteRelatedEntries(DeleteVariants):
pass pass
class DeleteHomonymy(NoReset):
def update_model(self, model):
for el in document.getElementsByClassName("list-adder-input"):
el.value = ""
class DeleteEntryLabels(NoReset): class DeleteEntryLabels(NoReset):
def update_model(self, model): def update_model(self, model):
for sel in document.getElementsByClassName("label-value"): for sel in document.getElementsByClassName("label-value"):

View File

@ -30,12 +30,6 @@ class ShowVariantsEdit(ClickMessage):
model.modal_set(lambda: modals.edit_variants(model.entry)) model.modal_set(lambda: modals.edit_variants(model.entry))
class ShowHomonymyEdit(ClickMessage):
def update_model(self, model):
model.entry.make_copy()
model.modal_set(lambda: modals.edit_homonymy(model.entry))
class ShowRelatedEntriesEdit(ClickMessage): class ShowRelatedEntriesEdit(ClickMessage):
def update_model(self, model): def update_model(self, model):
model.entry.make_copy() model.entry.make_copy()

View File

@ -88,11 +88,6 @@ class EditVariants(Message):
variants = common_accessors.generic_list_getter() variants = common_accessors.generic_list_getter()
model.entry.variants = variants model.entry.variants = variants
class EditHomonymy(Message):
def update_model(self, model):
homonymy = common_accessors.double_list_getter("value", "name")
model.entry.homonymy = homonymy
class EditRelatedEntries(Message): class EditRelatedEntries(Message):
def update_model(self, model): def update_model(self, model):

View File

@ -26,7 +26,6 @@ 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):
@ -59,8 +58,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.gramrel = data.gramrel self.structure_name, self.structure_id = convert_structure(data.gramrel)
self.structure_name, self.structure, self.structure_id = convert_structure(data.gramrel, data.lempos)
self.other = {"score": data.score, "cm": data.cm} self.other = {"score": data.score, "cm": data.cm}
@ -103,28 +101,13 @@ def match_gf2_examples(data, *args):
xhr.send(to_send) xhr.send(to_send)
def make_cql_query(ske_index, search_term, pos):
cql_pos= {
"samostalnik": ("S.*", "-s"),
"glagol": ("G.*", "-g"),
"pridevnik": ("P.*", "-p"),
"prislov": ("R.*", "-r"),
"zaimek": ("Z.*", "-z")
}
if ske_index == 0:
return "[ lemma=\"{0}\" & tag=\"{1}\" ]".format(search_term, cql_pos[pos][0])
else:
return search_term + cql_pos[pos][1]
class SkeModal(ClickMessage): class SkeModal(ClickMessage):
def on_event(self, event): def on_event(self, event):
# event could be data if this is the return from external library # event could be data if this is the return from external library
if type(event) in [list, int]: if type(event) in [list, int]:
self.add_arg(event) self.add_arg(event)
else: else:
if len(self._args) < 5: if len(self._args) < 4:
self.add_arg(None) self.add_arg(None)
super().on_event(event) super().on_event(event)
@ -132,20 +115,18 @@ class SkeModal(ClickMessage):
page_num = self.get_arg(0, int) page_num = self.get_arg(0, int)
search_term = self.get_arg(1, str) search_term = self.get_arg(1, str)
ske_index = self.get_arg(2, int) ske_index = self.get_arg(2, int)
ske_pos_query = self.get_arg(3, str)
ske_lookup = model.ske.url_for_kind_index(ske_index) ske_lookup = model.ske.url_for_kind_index(ske_index)
next_message = msg(SkeModal, page_num, search_term, ske_index, ske_pos_query) next_message = msg(SkeModal, page_num, search_term, ske_index)
# could be none if empty # could be none if empty
data = self.get_arg(4) data = self.get_arg(3)
if data is None: if data is None:
params = {"additional_refs": "s.id,p.id", params = {"additional_refs": "s.id,p.id",
"page_num": page_num, "page_num": page_num,
"error_callback": next_message, "error_callback": next_message,
"data_parser": get_parser(ske_index), "data_parser": get_parser(ske_index)}
"querytype": ske_pos_query}
gdex = get_preference("ske_gdex") gdex = get_preference("ske_gdex")
if gdex: if gdex:
@ -154,36 +135,15 @@ class SkeModal(ClickMessage):
return return
params["gdex"] = gdex params["gdex"] = gdex
# enable CQL query
if ske_pos_query is not "simple":
search_term_old = search_term
search_term = make_cql_query(ske_index, search_term, ske_pos_query)
model.ske.request(search_term, next_message, ske_lookup, params) model.ske.request(search_term, next_message, ske_lookup, params)
search_term = search_term_old
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 not data[0].gf2_check and type(data[0]) is SkeExample: if data[0].gf2_good is None:
# 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, ske_pos_query) match_gf2_examples(data, page_num, search_term, ske_index)
elif type(data[0]) is SkeCollocation:
# filtering, grouping and sorting data
data.sort(key= lambda x: float(x.other["score"]), reverse=True)
_data = []
while len(data) > 0:
max_item = data.pop(0) # max(data, key= lambda x: x.other["score"])
_data.append(max_item)
for item in data:
if "N/A" in item.structure_name:
data.remove(item)
elif item.structure_name.strip() == max_item.structure_name.strip():
_data.append(item)
for delete_item in _data:
if delete_item in data:
data.remove(delete_item)
data = _data
model.modal_set(lambda: modals.ske_list( model.modal_set(lambda: modals.ske_list(
search_term, data, page_num, model.entry.senses, model.ske.request_kinds)) search_term, data, page_num, model.entry.senses, model.ske.request_kinds))
@ -194,25 +154,19 @@ class SkeModal(ClickMessage):
class SkeModalGf2Update(SkeModal): class SkeModalGf2Update(SkeModal):
def on_event(self, event): def on_event(self, event):
response_data = window.JSON.parse(event.target.response) response_data = window.JSON.parse(event.target.response)
data = self.get_arg(4) data = self.get_arg(3)
data_dict = {} data_dict = {}
for example in data: for example in data:
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
@ -230,7 +184,6 @@ class SearchInSkeModal(SkeModal):
self.add_arg(int(document.getElementById("ske-page-num").value)) self.add_arg(int(document.getElementById("ske-page-num").value))
self.add_arg(document.getElementById("ske-search").value) self.add_arg(document.getElementById("ske-search").value)
self.add_arg(document.getElementById("ske-select").selectedIndex) self.add_arg(document.getElementById("ske-select").selectedIndex)
self.add_arg(document.getElementById("ske-pos-query").value)
super().on_event(event) super().on_event(event)
@ -264,12 +217,10 @@ class SkeInsert(DataChgClickMessage):
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()
new_example.inner = CorpusExample() new_example.inner = CorpusExample()
new_example.inner.other_attributes["example_id"] = example.s_id new_example.inner.other_attributes["exampleId"] = example.s_id
new_example.inner.cluster = ExampleClusters.first_empty_cluster() new_example.inner.cluster = ExampleClusters.first_empty_cluster()
lex_left = ComponentLexeme() lex_left = ComponentLexeme()
@ -292,50 +243,21 @@ class SkeInsert(DataChgClickMessage):
new_collocation.inner = MultiwordExample() new_collocation.inner = MultiwordExample()
new_collocation.inner.other_attributes["structure_id"] = example.structure_id new_collocation.inner.other_attributes["structure_id"] = example.structure_id
new_collocation.inner.other_attributes["structureName"] = example.structure_name
new_collocation.inner.other_attributes["logDice"] = example.other["score"] new_collocation.inner.other_attributes["logDice"] = example.other["score"]
new_collocation.inner.other_attributes["frequency"] = example.frequency new_collocation.inner.other_attributes["frequency"] = example.frequency
new_collocation.inner.type = "collocation" new_collocation.inner.type = "collocation"
headword = document.getElementById("ske-search").value lex_left = ComponentLexeme()
lexemes = [] lex_left.text = ""
structure_name = example.structure_name.split("-") lex_left.role = None
gramrel = example.gramrel.split("_")
structure = example.structure.split(" ")
structure.append("") # Bad fix: we have to add something for structure l-gg-ggn
for i in range(len(structure_name)): lex_mid = ComponentLexeme()
lex = ComponentLexeme() lex_mid.text = example.word
structure[i] = structure[i].replace("Inf-", "") lex_mid.role = "headword"
# take care of negations "ne" lex_right = ComponentLexeme()
if "Neg-" in structure[i]: lex_right.text = ""
structure[i] = structure[i].replace("Neg-", "") lex_right.role = None
negation_flag = True
n_lex = ComponentLexeme()
n_lex.text = "ne"
n_lex.role = "other"
lexemes.append(n_lex)
if structure[i] is "": new_collocation.components.extend([lex_left, lex_mid, lex_right])
continue # skipping bcs of fix
elif "Vez-gbz" in structure[i]:
lex.text = "je"
lex.role = "other"
elif structure_name[i] in ["d", "vd", "zp"]:
lex.text = gramrel[i]
lex.text = lex.text.replace("-d", "").replace("%", "")
lex.role = "other"
elif structure_name[i] is "vp":
lex.text = structure[i]
lex.role = "other"
elif structure[i][0] in ["S", "G", "P", "R"]:
lex.text = headword
lex.role = "headword"
else:
lex.text = example.word
lex.role = "collocate"
lexemes.append(lex)
new_collocation.components.extend(lexemes)
return new_collocation return new_collocation

View File

@ -4,7 +4,6 @@ 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
@ -14,14 +13,8 @@ class EditTranslation(DataChgClickMessage):
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
# This could be dangerous if double_list_getter is getting data from any other list as well. self.translation.explanation = document.getElementById("ete").value
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()

View File

@ -2,4 +2,3 @@ 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

View File

@ -12,9 +12,7 @@ class Entry(Data):
def __init__(self): def __init__(self):
self.status = "" self.status = ""
self.headword = "" self.headword = ""
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 = []
@ -23,24 +21,19 @@ 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 and headword.hasAttribute("type") else None self.headword_type = headword.getAttribute("type") if headword 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")]
self.homonymy = [{"value": v.textContent, "name": v.getAttribute("name")} for v in entry_xml.querySelectorAll("head headword homonymy homonymyFeature ")]
self.related_entries = [re.textContent for re in entry_xml.querySelectorAll("head relatedEntryList relatedEntry")] self.related_entries = [re.textContent for re in entry_xml.querySelectorAll("head relatedEntryList relatedEntry")]
lex_unit = entry_xml.querySelector("lexical_unit lexeme,lexicalUnit lexeme") lex_unit = entry_xml.querySelector("lexical_unit lexeme,lexicalUnit lexeme")
@ -87,8 +80,7 @@ class Entry(Data):
h("button.normal", clk(M.ShowVariantsEdit), "Variante"), h("button.normal", clk(M.ShowVariantsEdit), "Variante"),
h("button.success", clk(M.ShowRelatedEntriesEdit), "Povezano"), h("button.success", clk(M.ShowRelatedEntriesEdit), "Povezano"),
h("button.success", clk(M.ShowEntryLabelsEdit), "Oznake"), h("button.success", clk(M.ShowEntryLabelsEdit), "Oznake"),
h("button.normal", clk(M.ShowCommentEdit), "Opombe"), h("button.normal", clk(M.ShowCommentEdit), "Opombe")]
h("button.normal", clk(M.ShowHomonymyEdit), "Homonomije"),]
view_buttons = [] view_buttons = []
view_table = [] view_table = []
@ -98,11 +90,6 @@ class Entry(Data):
else: else:
view_table.append((buttons[0], ", ".join(self.variants))) view_table.append((buttons[0], ", ".join(self.variants)))
if len(self.homonymy) == 0:
view_buttons.append(buttons[4])
else:
view_table.append((buttons[4], ", ".join((h["name"] + ": " + h.value) for h in self.homonymy)))
if len(self.related_entries) == 0: if len(self.related_entries) == 0:
view_buttons.append(buttons[1]) view_buttons.append(buttons[1])
else: else:

View File

@ -19,10 +19,11 @@ 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 ["lexeme_id", "lexical_unit_lexeme_id", "slolex", "kol", "sloleks"]: for oth_attr in ["lexical_unit_lexeme_id", "slolex", "kol"]:
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)
@ -32,6 +33,7 @@ class ComponentLexeme(Data):
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

View File

@ -40,7 +40,7 @@ class Example(Data):
return example return example
def import_xml(self, example_xml): def import_xml(self, example_xml):
self.translations = from_container_list(example_xml.querySelectorAll("translationContainerList translationContainer")) self.translations = from_container_list(example_xml.querySelectorAll("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"

View File

@ -1,21 +0,0 @@
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

View File

@ -18,14 +18,14 @@ class Sense(Data):
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('sense > translationContainerList translationContainer')) sense_xml.querySelectorAll("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)

View File

@ -1,5 +1,4 @@
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
@ -33,8 +32,7 @@ class Translation(Data):
self.translation = "" self.translation = ""
self.source = "" self.source = ""
self.targetLang = "" self.targetLang = ""
self.audio = "" self.explanation = ""
self.explanationList = set()
self.tags = [] self.tags = []
def import_xml(self, translation_xml): def import_xml(self, translation_xml):
@ -44,16 +42,12 @@ class Translation(Data):
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 ""
explanationList = translation_xml.querySelectorAll("explanationList explanation")
for explanation_dom in explanationList:
explanation = Explanation()
explanation.import_dom(explanation_dom)
self.explanationList.append(explanation)
explanation = translation_xml.querySelector("explanation")
self.explanation = explanation.textContent if explanation else ""
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 = []
@ -67,10 +61,8 @@ class Translation(Data):
if self.source: if self.source:
elements.append(h("span.translation-source", {}, self.source)) elements.append(h("span.translation-source", {}, self.source))
if (self.explanationList): explanation_class = ".translation-explanation" if self.translation else ""
explanation_class = ".explanations" if self.translation else ".explanations.solo" elements.append(h("span{}".format(explanation_class), {}, self.explanation))
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)
@ -81,6 +73,6 @@ class Translation(Data):
# 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 len(self.explanationList) == 0 result = result and self.explanation == ""
result = result and len(self.tags) == 0 result = result and len(self.tags) == 0
return result return result

View File

@ -47,47 +47,6 @@ def generic_list_editor(title, element_list_getter):
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, element_list_getter)}}, "+")) content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, element_list_getter)}}, "+"))
return content return content
def homonymy_editor(title, current_labels):
def split_line2(left, right):
cls = "flex.two{}".format(".double-list-row")
return h("div.{}".format(cls), {}, [
h("div.half", {}, left), h("div.half", {}, right)])
content = [h("p", {}, title)]
for i, feature in enumerate(current_labels()):
name = []
value = []
name.append(h("label", {"attrs": {"for": i}}, "Name:"))
name.append(h("input.name-input", {"props": {"type": "text", "value": feature["name"], "id": i}}, ""))
value.append(h("label", {"attrs": {"for": i + "-value"}}, "Value:"))
value.append(h("input.value-input", {"props": {"type": "text", "value": feature["value"], "id": i + "-value"}}, ""))
content.append(split_line2(name, value))
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, current_labels)}}, "+"))
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):

View File

@ -19,9 +19,10 @@ 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:", h("textarea#etv", {"props": {"value": translation.translation}}, ""))]) split_line2("Prevedek:",
h("textarea#etv", {"props": {"value": translation.translation}}, "")),
content.extend(explanation_editor("Razlage:", lambda: translation.explanationList)) split_line2("Razlaga:",
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)]
@ -64,7 +65,6 @@ def edit_example(example, sense):
result.append(h("span.example-component-button.example-component-none", result.append(h("span.example-component-button.example-component-none",
{"on": {"click": role_msg(idx, "none")}}, "N")) {"on": {"click": role_msg(idx, "none")}}, "N"))
if "-" not in example.inner.other_attributes["structureName"]:
result.extend([ result.extend([
h("span.example-component-button", h("span.example-component-button",
{"on": {"click": message.msg(message.ExampleComponentAdd, example_original, idx)}}, "+"), {"on": {"click": message.msg(message.ExampleComponentAdd, example_original, idx)}}, "+"),
@ -73,9 +73,6 @@ def edit_example(example, sense):
return result return result
divs.append(h("div.flex.five.example-component", {}, [h("div.one-fifth", {}, "Struktura:"),
h("div.three-fifth", {}, example.inner.other_attributes["structureName"])]))
for idx, component in enumerate(example.components): for idx, component in enumerate(example.components):
role_txt = component.role if component.role is not None else "none" role_txt = component.role if component.role is not None else "none"
color_class = ".example-component-" + role_txt color_class = ".example-component-" + role_txt
@ -102,12 +99,6 @@ def edit_variants(entry):
return modal_template(content, "Add or remove variants", (message.EditVariants,), (message.DeleteVariants,)) return modal_template(content, "Add or remove variants", (message.EditVariants,), (message.DeleteVariants,))
def edit_homonymy(entry):
hget = lambda: entry.copy().homonymy
content = homonymy_editor("Homonymy", hget)
return modal_template(content, "Add or remove homonymy features", (message.EditHomonymy,), (message.DeleteHomonymy,))
def edit_related_entries(entry): def edit_related_entries(entry):
reget = lambda: entry.copy().related_entries reget = lambda: entry.copy().related_entries
content = generic_list_editor("Related entries", reget) content = generic_list_editor("Related entries", reget)
@ -181,10 +172,6 @@ def ske_list(search_term, data, page_num, senses, ske_kinds):
"type": "number", "type": "number",
"min": 1, "min": 1,
"step": 1}}, "")]), "step": 1}}, "")]),
h("label.fourth.ske-mid-input", {}, [
h("select#ske-pos-query", {}, [h("option", {}, "{}".format(pos)) for pos in ["simple", "samostalnik", "glagol", "pridevnik", "prislov", "zaimek"]])
]),
h("span.fourth.button.ske-right-button", h("span.fourth.button.ske-right-button",
{"on": {"click": message.msg(message.SearchInSkeModal)}}, "Isci")]), {"on": {"click": message.msg(message.SearchInSkeModal)}}, "Isci")]),
h("div.ske-list", h("div.ske-list",

View File

@ -58,7 +58,7 @@ class View:
def view_ske_button(model): def view_ske_button(model):
return h( return h(
"span#ske-button.button.toggle", "span#ske-button.button.toggle",
{ "on": {"click": msg(ShowSkeModal, 1, model.entry.headword, 0, "simple")} }, { "on": {"click": msg(ShowSkeModal, 1, model.entry.headword, 0)} },
h("svg#ske-img", { h("svg#ske-img", {
"attrs": { "attrs": {
"xmlns": "http://www.w3.org/2000/svg", "xmlns": "http://www.w3.org/2000/svg",