updated ske interface: better formatting, using gdex, using example.s_id, multiple pages

This commit is contained in:
Ozbolt Menegatti 2020-04-22 14:20:34 +02:00
parent e29b7f503d
commit b24a6f0a07
6 changed files with 85 additions and 45 deletions

View File

@ -212,23 +212,6 @@
}
}
.example-cluster, .example-logdice, .example-frequency {
vertical-align: super;
font-size: 0.7em;
margin-left: 0.1em;
margin-right: 0.1em;
}
.example-cluster {
color: @blue;
}
.example-logdice {
color: @gray;
}
.example-frequency {
color: @darkred;
}
.example-rest {
border: 1px transparent solid;
@ -266,6 +249,26 @@
margin-top: 0.3em;
}
.example-text {
.example-cluster, .example-logdice, .example-frequency {
vertical-align: super;
font-size: 0.7em;
margin-left: 0.1em;
margin-right: 0.1em;
}
.example-cluster {
color: @blue;
}
.example-logdice {
color: @gray;
}
.example-frequency {
color: @darkred;
}
}
.example-component {
.example-component-button {
padding-left: 0.3em;

8
src/lib/preferences.py Normal file
View File

@ -0,0 +1,8 @@
from browser import window
# interface to plugin properties
def get_preference(key):
return window.customizeEditor[key] if window.customizeEditor else None

View File

@ -3,11 +3,14 @@ from message.message import msg, Message
from view import modals
from browser import window, document
from lib.snabbdom import h
from lib.preferences import get_preference
from lib.structure_conversions import convert_structure
from model.example.example import Example
from model.example.corpus_example import CorpusExample
from model.example.multiword_example import MultiwordExample
from model.example.component_lexeme import ComponentLexeme
from model.example_clusters import ExampleClusters
class SkeExample:
@ -15,6 +18,7 @@ class SkeExample:
self.left = ""
self.right = ""
self.mid = ""
self.s_id = ""
for left_el in line.Left:
self.left += left_el.str
@ -25,6 +29,11 @@ class SkeExample:
for mid_el in line.Kwic:
self.mid += mid_el.str
for ref in line.Refs:
if ref.startswith("s.id"):
self.s_id = ref.split("=")[1]
def view(self):
return [h("span", {}, self.left + " "),
h("span", {"style": {"font-weight": "bold"}}, self.mid),
@ -40,16 +49,14 @@ class SkeCollocation:
self.other = {"score": data.score, "cm": data.cm}
def view(self):
return [
h("span.grey1", {}, self.word),
return [h("span.example-text", {}, [
h("span.example-text-2", {}, self.word),
h("span.example-frequency", {}, self.frequency),
h("span.example-logdice", {}, self.other["score"]),
h("span", {}, "; "),
h("span.grey1", {}, self.other["cm"]),
h("span", {}, ","),
h("span.grey2", {}, self.frequency),
h("span", {}, ","),
h("span.grey1", {}, self.other["score"]),
h("span", {}, ","),
h("span.grey2", {}, self.other["cm"]),
h("span", {}, ","),
h("span.grey1", {}, self.structure_name)]
h("span.grey2", {}, self.structure_name)])]
def get_parser(ske_index_type):
@ -67,26 +74,38 @@ class SkeModal(ClickMessage):
if type(event) in [list, int]:
self.add_arg(event)
else:
if len(self._args) < 3:
if len(self._args) < 4:
self.add_arg(None)
super().on_event(event)
def update_model(self, model):
search_term = self.get_arg(0, str)
ske_index = self.get_arg(1, int)
page_num = self.get_arg(0, int)
search_term = self.get_arg(1, str)
ske_index = self.get_arg(2, int)
ske_lookup = model.ske.url_for_kind_index(ske_index)
# could be none if empty
data = self.get_arg(2)
data = self.get_arg(3)
if data is None:
model.ske.request(search_term,
msg(SkeModal, search_term, ske_index),
ske_lookup,
{"additional_refs": "s.id,p.id",
"error_callback": msg(SkeModal, search_term, ske_index),
"data_parser": get_parser(ske_index)})
params = {"additional_refs": "s.id,p.id",
"page_num": page_num,
"error_callback": msg(SkeModal, page_num, search_term, ske_index),
"data_parser": get_parser(ske_index)}
model.modal_set(lambda: modals.ske_list(search_term, data, model.entry.senses, model.ske.request_kinds))
gdex = get_preference("ske_gdex")
if gdex:
if not len(gdex) == 2:
window.console.log("Strange gdex setting, should be a list of length 2: [gdexconf, gdexcnt]")
return
params["gdex"] = gdex
model.ske.request(search_term,
msg(SkeModal, page_num, search_term, ske_index),
ske_lookup,
params)
model.modal_set(lambda: modals.ske_list(
search_term, data, page_num, model.entry.senses, model.ske.request_kinds))
def reset(self):
return False
@ -101,6 +120,7 @@ class ShowSkeModal(SkeModal):
class SearchInSkeModal(SkeModal):
def on_event(self, event):
self.add_arg(int(document.getElementById("ske-page-num").value))
self.add_arg(document.getElementById("ske-search").value)
self.add_arg(document.getElementById("ske-select").selectedIndex)
super().on_event(event)
@ -139,6 +159,8 @@ class SkeInsert(DataChgClickMessage):
def _as_corpus_example(self, example):
new_example = Example()
new_example.inner = CorpusExample()
new_example.inner.other_attributes["example_id"] = example.s_id
new_example.inner.cluster = ExampleClusters.first_empty_cluster()
lex_left = ComponentLexeme()
lex_left.text = example["left"]

View File

@ -22,12 +22,13 @@ class Example(Data):
inner_xml = example_xml.querySelector("corpusExample")
if inner_xml is not None:
self.inner = CorpusExample(inner_xml)
self.inner = CorpusExample()
else:
inner_xml = example_xml.querySelector("multiwordExample")
self.inner = MultiwordExample()
self.inner.import_xml(inner_xml)
self.inner.import_xml(inner_xml)
for comp_xml in inner_xml.childNodes:
comp = ComponentLexeme()
comp.import_xml(comp_xml)

View File

@ -131,7 +131,7 @@ def do_chosen_examples(example_list, entry):
return modal_template(options, "Examples picker", (message.DoChosenExamples, example_list))
def ske_list(search_term, data, senses, ske_kinds):
def ske_list(search_term, data, page_num, senses, ske_kinds):
list_contents = []
ske_list_hidden = False
@ -148,12 +148,18 @@ def ske_list(search_term, data, senses, ske_kinds):
list_contents.append(h("span.error", {}, "Something went wrong in SKE: {}".format(data)))
contents = [
h("div.flex.three", {}, [
h("select#ske-select.third", {}, [
h("div.flex.four", {}, [
h("select#ske-select.fourth", {}, [
h("option", {}, "{}".format(x)) for x in ske_kinds]),
h("label.third.ske-mid-input", {}, [
h("label.fourth.ske-mid-input", {}, [
h("input#ske-search", {"props": {"value": search_term, "type": "text"}}, "")]),
h("span.third.button.ske-right-button",
h("label.fourth.ske-mid-input", {}, [
h("input#ske-page-num", {"attrs": {
"value": str(page_num),
"type": "number",
"min": 1,
"step": 1}}, "")]),
h("span.fourth.button.ske-right-button",
{"on": {"click": message.msg(message.SearchInSkeModal)}}, "Isci")]),
h("div.ske-list",
{"style": {"visibility": "hidden" if ske_list_hidden else "visible"}},

View File

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