From 3926d1a199fa63e29885d30ba6f2b15b3270d594 Mon Sep 17 00:00:00 2001 From: LukeItUp Date: Tue, 4 Aug 2020 09:48:17 +0200 Subject: [PATCH 1/2] Feature#1405 and Bug#1399 --- .gitignore | 2 +- src/lib/structure_conversions.py | 17 ++++++++++++++--- src/message/ske_messages.py | 25 +++++++++++++------------ 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index a67997d..f37fcbb 100644 --- a/.gitignore +++ b/.gitignore @@ -10,5 +10,5 @@ build/* # using kdev4, works fairly nicely! .kdev4 **/*.kdev4 - +remote diff --git a/src/lib/structure_conversions.py b/src/lib/structure_conversions.py index 5e408fc..5852c6f 100644 --- a/src/lib/structure_conversions.py +++ b/src/lib/structure_conversions.py @@ -34,19 +34,30 @@ def build_structure_conversions(): structure_conversions.append((__new__(RegExp(vfrom, 'u')), vto_name, vto_id)) -def convert_structure(structure): +def convert_structure(structure, type): if structure_conversions is None: build_structure_conversions() for vfrom, vto_name, vto_id in structure_conversions: match = structure.match(vfrom) + # fix for ids 65, 66, 67 which instead matched with 64 + if match and vto_id == '64' and '-s' in type: + vto_name = 's0-vp-s0' + vto_id = '65' + elif match and vto_id == '64' and '-g' in type: + vto_name = 'gg-vp-gg' + vto_id = '66' + elif match and vto_id == '64' and '-r' in type: + vto_name = 'r-vp-r' + vto_id = '67' + if match: # we need to remove replace alias here as we want to use javascript's one __pragma__('noalias', 'replace') result = structure.replace(vfrom, vto_name).strip() __pragma__('alias', 'replace', "py_replace") - + return result, vto_id window.console.log("Unknown structure: ", structure) - return None + return 'N/A', '/' diff --git a/src/message/ske_messages.py b/src/message/ske_messages.py index 9769f3a..f51b071 100644 --- a/src/message/ske_messages.py +++ b/src/message/ske_messages.py @@ -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,7 @@ 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.structure_name, self.structure_id = convert_structure(data.gramrel, data.lempos) self.other = {"score": data.score, "cm": data.cm} @@ -79,7 +72,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: @@ -148,7 +141,7 @@ class SkeModal(ClickMessage): 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) @@ -169,12 +162,18 @@ class SkeModalGf2Update(SkeModal): 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 @@ -224,11 +223,13 @@ 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() 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() lex_left = ComponentLexeme() From a7f85accce64724479e49a0f1c7642ae2212df4a Mon Sep 17 00:00:00 2001 From: LukeItUp Date: Tue, 4 Aug 2020 10:05:36 +0200 Subject: [PATCH 2/2] fix unwanted line change --- src/message/ske_messages.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/message/ske_messages.py b/src/message/ske_messages.py index f51b071..8075fd5 100644 --- a/src/message/ske_messages.py +++ b/src/message/ske_messages.py @@ -229,7 +229,7 @@ class SkeInsert(DataChgClickMessage): def _as_corpus_example(self, example): new_example = Example() new_example.inner = CorpusExample() - new_example.inner.other_attributes["exampleId"] = example.s_id + new_example.inner.other_attributes["example_id"] = example.s_id new_example.inner.cluster = ExampleClusters.first_empty_cluster() lex_left = ComponentLexeme()