cql query option

This commit is contained in:
Luka Kavčič 2020-09-15 08:38:44 +02:00
parent 37980d56e5
commit 300f90822c
3 changed files with 36 additions and 8 deletions

View File

@ -103,13 +103,28 @@ 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) < 4: if len(self._args) < 5:
self.add_arg(None) self.add_arg(None)
super().on_event(event) super().on_event(event)
@ -117,18 +132,20 @@ 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) next_message = msg(SkeModal, page_num, search_term, ske_index, ske_pos_query)
# could be none if empty # could be none if empty
data = self.get_arg(3) data = self.get_arg(4)
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:
@ -137,14 +154,20 @@ 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 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, ske_pos_query)
elif type(data[0]) is SkeCollocation: elif type(data[0]) is SkeCollocation:
# filtering, grouping and sorting data # filtering, grouping and sorting data
data.sort(key= lambda x: float(x.other["score"]), reverse=True) data.sort(key= lambda x: float(x.other["score"]), reverse=True)
@ -171,7 +194,7 @@ 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(3) data = self.get_arg(4)
data_dict = {} data_dict = {}
for example in data: for example in data:
@ -207,6 +230,7 @@ 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)

View File

@ -181,6 +181,10 @@ 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)} }, { "on": {"click": msg(ShowSkeModal, 1, model.entry.headword, 0, "simple")} },
h("svg#ske-img", { h("svg#ske-img", {
"attrs": { "attrs": {
"xmlns": "http://www.w3.org/2000/svg", "xmlns": "http://www.w3.org/2000/svg",