updated ske interface: better formatting, using gdex, using example.s_id, multiple pages
This commit is contained in:
parent
e29b7f503d
commit
b24a6f0a07
|
@ -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 {
|
.example-rest {
|
||||||
border: 1px transparent solid;
|
border: 1px transparent solid;
|
||||||
|
@ -266,6 +249,26 @@
|
||||||
margin-top: 0.3em;
|
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 {
|
||||||
.example-component-button {
|
.example-component-button {
|
||||||
padding-left: 0.3em;
|
padding-left: 0.3em;
|
||||||
|
|
8
src/lib/preferences.py
Normal file
8
src/lib/preferences.py
Normal 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
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,14 @@ from message.message import msg, Message
|
||||||
from view import modals
|
from view import modals
|
||||||
from browser import window, document
|
from browser import window, document
|
||||||
from lib.snabbdom import h
|
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.example import Example
|
||||||
from model.example.corpus_example import CorpusExample
|
from model.example.corpus_example import CorpusExample
|
||||||
from model.example.multiword_example import MultiwordExample
|
from model.example.multiword_example import MultiwordExample
|
||||||
from model.example.component_lexeme import ComponentLexeme
|
from model.example.component_lexeme import ComponentLexeme
|
||||||
|
from model.example_clusters import ExampleClusters
|
||||||
|
|
||||||
|
|
||||||
class SkeExample:
|
class SkeExample:
|
||||||
|
@ -15,6 +18,7 @@ class SkeExample:
|
||||||
self.left = ""
|
self.left = ""
|
||||||
self.right = ""
|
self.right = ""
|
||||||
self.mid = ""
|
self.mid = ""
|
||||||
|
self.s_id = ""
|
||||||
|
|
||||||
for left_el in line.Left:
|
for left_el in line.Left:
|
||||||
self.left += left_el.str
|
self.left += left_el.str
|
||||||
|
@ -25,6 +29,11 @@ class SkeExample:
|
||||||
for mid_el in line.Kwic:
|
for mid_el in line.Kwic:
|
||||||
self.mid += mid_el.str
|
self.mid += mid_el.str
|
||||||
|
|
||||||
|
for ref in line.Refs:
|
||||||
|
if ref.startswith("s.id"):
|
||||||
|
self.s_id = ref.split("=")[1]
|
||||||
|
|
||||||
|
|
||||||
def view(self):
|
def view(self):
|
||||||
return [h("span", {}, self.left + " "),
|
return [h("span", {}, self.left + " "),
|
||||||
h("span", {"style": {"font-weight": "bold"}}, self.mid),
|
h("span", {"style": {"font-weight": "bold"}}, self.mid),
|
||||||
|
@ -40,16 +49,14 @@ class SkeCollocation:
|
||||||
self.other = {"score": data.score, "cm": data.cm}
|
self.other = {"score": data.score, "cm": data.cm}
|
||||||
|
|
||||||
def view(self):
|
def view(self):
|
||||||
return [
|
return [h("span.example-text", {}, [
|
||||||
h("span.grey1", {}, self.word),
|
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", {}, ","),
|
||||||
h("span.grey2", {}, self.frequency),
|
h("span.grey2", {}, self.structure_name)])]
|
||||||
h("span", {}, ","),
|
|
||||||
h("span.grey1", {}, self.other["score"]),
|
|
||||||
h("span", {}, ","),
|
|
||||||
h("span.grey2", {}, self.other["cm"]),
|
|
||||||
h("span", {}, ","),
|
|
||||||
h("span.grey1", {}, self.structure_name)]
|
|
||||||
|
|
||||||
|
|
||||||
def get_parser(ske_index_type):
|
def get_parser(ske_index_type):
|
||||||
|
@ -67,26 +74,38 @@ class SkeModal(ClickMessage):
|
||||||
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) < 3:
|
if len(self._args) < 4:
|
||||||
self.add_arg(None)
|
self.add_arg(None)
|
||||||
super().on_event(event)
|
super().on_event(event)
|
||||||
|
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
search_term = self.get_arg(0, str)
|
page_num = self.get_arg(0, int)
|
||||||
ske_index = self.get_arg(1, 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)
|
ske_lookup = model.ske.url_for_kind_index(ske_index)
|
||||||
|
|
||||||
# could be none if empty
|
# could be none if empty
|
||||||
data = self.get_arg(2)
|
data = self.get_arg(3)
|
||||||
if data is None:
|
if data is None:
|
||||||
model.ske.request(search_term,
|
params = {"additional_refs": "s.id,p.id",
|
||||||
msg(SkeModal, search_term, ske_index),
|
"page_num": page_num,
|
||||||
ske_lookup,
|
"error_callback": msg(SkeModal, page_num, search_term, ske_index),
|
||||||
{"additional_refs": "s.id,p.id",
|
"data_parser": get_parser(ske_index)}
|
||||||
"error_callback": msg(SkeModal, 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):
|
def reset(self):
|
||||||
return False
|
return False
|
||||||
|
@ -101,6 +120,7 @@ class ShowSkeModal(SkeModal):
|
||||||
|
|
||||||
class SearchInSkeModal(SkeModal):
|
class SearchInSkeModal(SkeModal):
|
||||||
def on_event(self, event):
|
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-search").value)
|
||||||
self.add_arg(document.getElementById("ske-select").selectedIndex)
|
self.add_arg(document.getElementById("ske-select").selectedIndex)
|
||||||
super().on_event(event)
|
super().on_event(event)
|
||||||
|
@ -139,6 +159,8 @@ class SkeInsert(DataChgClickMessage):
|
||||||
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.cluster = ExampleClusters.first_empty_cluster()
|
||||||
|
|
||||||
lex_left = ComponentLexeme()
|
lex_left = ComponentLexeme()
|
||||||
lex_left.text = example["left"]
|
lex_left.text = example["left"]
|
||||||
|
|
|
@ -22,12 +22,13 @@ class Example(Data):
|
||||||
|
|
||||||
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(inner_xml)
|
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 comp_xml in inner_xml.childNodes:
|
for comp_xml in inner_xml.childNodes:
|
||||||
comp = ComponentLexeme()
|
comp = ComponentLexeme()
|
||||||
comp.import_xml(comp_xml)
|
comp.import_xml(comp_xml)
|
||||||
|
|
|
@ -131,7 +131,7 @@ def do_chosen_examples(example_list, entry):
|
||||||
return modal_template(options, "Examples picker", (message.DoChosenExamples, example_list))
|
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 = []
|
list_contents = []
|
||||||
ske_list_hidden = False
|
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)))
|
list_contents.append(h("span.error", {}, "Something went wrong in SKE: {}".format(data)))
|
||||||
|
|
||||||
contents = [
|
contents = [
|
||||||
h("div.flex.three", {}, [
|
h("div.flex.four", {}, [
|
||||||
h("select#ske-select.third", {}, [
|
h("select#ske-select.fourth", {}, [
|
||||||
h("option", {}, "{}".format(x)) for x in ske_kinds]),
|
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("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")]),
|
{"on": {"click": message.msg(message.SearchInSkeModal)}}, "Isci")]),
|
||||||
h("div.ske-list",
|
h("div.ske-list",
|
||||||
{"style": {"visibility": "hidden" if ske_list_hidden else "visible"}},
|
{"style": {"visibility": "hidden" if ske_list_hidden else "visible"}},
|
||||||
|
|
|
@ -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, model.entry.headword, 0)} },
|
{ "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",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user