|
|
|
@ -26,6 +26,7 @@ class SkeExample:
|
|
|
|
|
self.mid = ""
|
|
|
|
|
self.s_id = ""
|
|
|
|
|
self.gf2_good = None
|
|
|
|
|
self.gf2_check = False
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def fromLine(line):
|
|
|
|
@ -58,15 +59,8 @@ class SkeCollocation:
|
|
|
|
|
def __init__(self, data):
|
|
|
|
|
self.word = data.word
|
|
|
|
|
self.frequency = data.count
|
|
|
|
|
|
|
|
|
|
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.gramrel = data.gramrel
|
|
|
|
|
self.structure_name, self.structure, self.structure_id = convert_structure(data.gramrel, data.lempos)
|
|
|
|
|
|
|
|
|
|
self.other = {"score": data.score, "cm": data.cm}
|
|
|
|
|
|
|
|
|
@ -79,7 +73,7 @@ class SkeCollocation:
|
|
|
|
|
h("span.grey1", {}, self.other["cm"]),
|
|
|
|
|
h("span", {}, ","),
|
|
|
|
|
h("span.grey2", {}, self.structure_name)])]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_parser(ske_index_type):
|
|
|
|
|
if ske_index_type == 0:
|
|
|
|
@ -109,13 +103,28 @@ def match_gf2_examples(data, *args):
|
|
|
|
|
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):
|
|
|
|
|
def on_event(self, event):
|
|
|
|
|
# event could be data if this is the return from external library
|
|
|
|
|
if type(event) in [list, int]:
|
|
|
|
|
self.add_arg(event)
|
|
|
|
|
else:
|
|
|
|
|
if len(self._args) < 4:
|
|
|
|
|
if len(self._args) < 5:
|
|
|
|
|
self.add_arg(None)
|
|
|
|
|
super().on_event(event)
|
|
|
|
|
|
|
|
|
@ -123,18 +132,20 @@ class SkeModal(ClickMessage):
|
|
|
|
|
page_num = self.get_arg(0, int)
|
|
|
|
|
search_term = self.get_arg(1, str)
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
data = self.get_arg(3)
|
|
|
|
|
data = self.get_arg(4)
|
|
|
|
|
|
|
|
|
|
if data is None:
|
|
|
|
|
params = {"additional_refs": "s.id,p.id",
|
|
|
|
|
"page_num": page_num,
|
|
|
|
|
"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")
|
|
|
|
|
if gdex:
|
|
|
|
@ -143,15 +154,36 @@ class SkeModal(ClickMessage):
|
|
|
|
|
return
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
search_term = search_term_old
|
|
|
|
|
|
|
|
|
|
elif type(data) is list:
|
|
|
|
|
window.console.log(data)
|
|
|
|
|
# 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
|
|
|
|
|
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:
|
|
|
|
|
# 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(
|
|
|
|
|
search_term, data, page_num, model.entry.senses, model.ske.request_kinds))
|
|
|
|
|
|
|
|
|
@ -162,19 +194,25 @@ class SkeModal(ClickMessage):
|
|
|
|
|
class SkeModalGf2Update(SkeModal):
|
|
|
|
|
def on_event(self, event):
|
|
|
|
|
response_data = window.JSON.parse(event.target.response)
|
|
|
|
|
data = self.get_arg(3)
|
|
|
|
|
data = self.get_arg(4)
|
|
|
|
|
|
|
|
|
|
data_dict = {}
|
|
|
|
|
for example in data:
|
|
|
|
|
example.gf_good = False
|
|
|
|
|
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"])
|
|
|
|
|
for gf_sid, gf_data in good_response.items():
|
|
|
|
|
data_dict[gf_sid].left = gf_data.left
|
|
|
|
|
data_dict[gf_sid].mid = gf_data.mid
|
|
|
|
|
data_dict[gf_sid].right = gf_data.right
|
|
|
|
|
data_dict[gf_sid].gf2_good = True
|
|
|
|
|
data_dict[gf_sid].gf2_check = True
|
|
|
|
|
|
|
|
|
|
# changed data_dict, now we can redraw!
|
|
|
|
|
# just let it do its thing in update_model
|
|
|
|
@ -192,6 +230,7 @@ class SearchInSkeModal(SkeModal):
|
|
|
|
|
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)
|
|
|
|
|
self.add_arg(document.getElementById("ske-pos-query").value)
|
|
|
|
|
super().on_event(event)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -224,6 +263,8 @@ class SkeInsert(DataChgClickMessage):
|
|
|
|
|
else:
|
|
|
|
|
console.log("You really should not be here, my lady")
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
model.reset()
|
|
|
|
|
|
|
|
|
|
def _as_corpus_example(self, example):
|
|
|
|
|
new_example = Example()
|
|
|
|
@ -237,7 +278,7 @@ class SkeInsert(DataChgClickMessage):
|
|
|
|
|
|
|
|
|
|
lex_mid = ComponentLexeme()
|
|
|
|
|
lex_mid.text = example["mid"]
|
|
|
|
|
lex_mid.role = "collocation"
|
|
|
|
|
lex_mid.role = "headword"
|
|
|
|
|
|
|
|
|
|
lex_right = ComponentLexeme()
|
|
|
|
|
lex_right.text = example["right"]
|
|
|
|
@ -256,17 +297,45 @@ class SkeInsert(DataChgClickMessage):
|
|
|
|
|
new_collocation.inner.other_attributes["frequency"] = example.frequency
|
|
|
|
|
new_collocation.inner.type = "collocation"
|
|
|
|
|
|
|
|
|
|
lex_left = ComponentLexeme()
|
|
|
|
|
lex_left.text = ""
|
|
|
|
|
lex_left.role = None
|
|
|
|
|
|
|
|
|
|
lex_mid = ComponentLexeme()
|
|
|
|
|
lex_mid.text = example.word
|
|
|
|
|
lex_mid.role = "collocation"
|
|
|
|
|
|
|
|
|
|
lex_right = ComponentLexeme()
|
|
|
|
|
lex_right.text = ""
|
|
|
|
|
lex_right.role = None
|
|
|
|
|
|
|
|
|
|
new_collocation.components.extend([lex_left, lex_mid, lex_right])
|
|
|
|
|
headword = document.getElementById("ske-search").value
|
|
|
|
|
lexemes = []
|
|
|
|
|
structure_name = example.structure_name.split("-")
|
|
|
|
|
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 = ComponentLexeme()
|
|
|
|
|
structure[i] = structure[i].replace("Inf-", "")
|
|
|
|
|
|
|
|
|
|
# take care of negations "ne"
|
|
|
|
|
if "Neg-" in structure[i]:
|
|
|
|
|
structure[i] = structure[i].replace("Neg-", "")
|
|
|
|
|
negation_flag = True
|
|
|
|
|
n_lex = ComponentLexeme()
|
|
|
|
|
n_lex.text = "ne"
|
|
|
|
|
n_lex.role = "other"
|
|
|
|
|
lexemes.append(n_lex)
|
|
|
|
|
|
|
|
|
|
if structure[i] is "":
|
|
|
|
|
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
|
|
|
|
|