From 8802a09c9cbb5f459587e5640d26a2f5da2ce5d5 Mon Sep 17 00:00:00 2001 From: LukeItUp Date: Tue, 25 Aug 2020 16:24:11 +0200 Subject: [PATCH 1/5] sort and filter collocations --- build/Makefile | 2 +- src/message/ske_messages.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/build/Makefile b/build/Makefile index ba3d85d..bd5ce05 100644 --- a/build/Makefile +++ b/build/Makefile @@ -30,7 +30,7 @@ all: build build: copy $(CSS_FILE) bundle.js local.js transcrypt: $(RES_PY_FILE) $(TS_BUILD) - transcrypt $(TS_FLAGS) $< + python3 -m transcrypt $(TS_FLAGS) $< bundle.js: transcrypt $(CONV_FILE) cd ..; browserify $(BR_FLAGS) build/$(TS_BUILD)/main.js -o build/bundle.js diff --git a/src/message/ske_messages.py b/src/message/ske_messages.py index 8075fd5..f54e636 100644 --- a/src/message/ske_messages.py +++ b/src/message/ske_messages.py @@ -144,6 +144,9 @@ class SkeModal(ClickMessage): 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) + elif type(data[0]) is SkeCollocation: + data.sort(key= lambda x: x.structure_name) + data = [x for x in data if x.structure_name is not "N/A"] model.modal_set(lambda: modals.ske_list( search_term, data, page_num, model.entry.senses, model.ske.request_kinds)) @@ -238,7 +241,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"] @@ -263,7 +266,7 @@ class SkeInsert(DataChgClickMessage): lex_mid = ComponentLexeme() lex_mid.text = example.word - lex_mid.role = "collocation" + lex_mid.role = "collocate" lex_right = ComponentLexeme() lex_right.text = "" -- 2.36.5 From 19d3e38dcbee5f604ebd9b6d0a195af430e896c9 Mon Sep 17 00:00:00 2001 From: LukeItUp Date: Thu, 3 Sep 2020 10:29:24 +0200 Subject: [PATCH 2/5] better collocation export --- src/lib/structure_conversions.py | 7 +-- src/message/ske_messages.py | 77 +++++++++++++++++++++++++------- 2 files changed, 64 insertions(+), 20 deletions(-) diff --git a/src/lib/structure_conversions.py b/src/lib/structure_conversions.py index 5852c6f..4ba8a8e 100644 --- a/src/lib/structure_conversions.py +++ b/src/lib/structure_conversions.py @@ -24,6 +24,7 @@ def build_structure_conversions(): if line[1] == "struktura": continue + vto_structure = line[1].strip().split(">")[1].split("<")[0] vto_name = line[2].strip() vto_id = line[4].strip() @@ -31,14 +32,14 @@ def build_structure_conversions(): continue vfrom = "^" + line[0].replace("?", "\?").replace("%s", "([a-zA-Z螚ȎŠ-]+)") + "$" - structure_conversions.append((__new__(RegExp(vfrom, 'u')), vto_name, vto_id)) + structure_conversions.append((__new__(RegExp(vfrom, 'u')), vto_name, vto_structure, vto_id)) def convert_structure(structure, type): if structure_conversions is None: build_structure_conversions() - for vfrom, vto_name, vto_id in structure_conversions: + for vfrom, vto_name, vto_structure, 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: @@ -57,7 +58,7 @@ def convert_structure(structure, type): result = structure.replace(vfrom, vto_name).strip() __pragma__('alias', 'replace', "py_replace") - return result, vto_id + return result, vto_structure, vto_id window.console.log("Unknown structure: ", structure) return 'N/A', '/' diff --git a/src/message/ske_messages.py b/src/message/ske_messages.py index f54e636..7faa743 100644 --- a/src/message/ske_messages.py +++ b/src/message/ske_messages.py @@ -59,7 +59,8 @@ class SkeCollocation: def __init__(self, data): self.word = data.word self.frequency = data.count - self.structure_name, self.structure_id = convert_structure(data.gramrel, data.lempos) + 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} @@ -145,9 +146,21 @@ class SkeModal(ClickMessage): # 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) elif type(data[0]) is SkeCollocation: - data.sort(key= lambda x: x.structure_name) - data = [x for x in data if x.structure_name is not "N/A"] - + # 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)) @@ -260,17 +273,47 @@ 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 = "collocate" - - 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)): + console.log("current:", i, "\ngramrel:", gramrel[i], "\nstructure:", structure[i], "\nstruc_name:", structure_name[i]) + + 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 -- 2.36.5 From 197cc6199c4f3f1534e387cf94645a6ece58eace Mon Sep 17 00:00:00 2001 From: LukeItUp Date: Thu, 3 Sep 2020 10:51:32 +0200 Subject: [PATCH 3/5] show structure at example edit --- build/Makefile | 2 +- src/message/ske_messages.py | 2 -- src/view/modals.py | 3 +++ 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/build/Makefile b/build/Makefile index bd5ce05..ba3d85d 100644 --- a/build/Makefile +++ b/build/Makefile @@ -30,7 +30,7 @@ all: build build: copy $(CSS_FILE) bundle.js local.js transcrypt: $(RES_PY_FILE) $(TS_BUILD) - python3 -m transcrypt $(TS_FLAGS) $< + transcrypt $(TS_FLAGS) $< bundle.js: transcrypt $(CONV_FILE) cd ..; browserify $(BR_FLAGS) build/$(TS_BUILD)/main.js -o build/bundle.js diff --git a/src/message/ske_messages.py b/src/message/ske_messages.py index 7faa743..9ef6b8e 100644 --- a/src/message/ske_messages.py +++ b/src/message/ske_messages.py @@ -281,8 +281,6 @@ class SkeInsert(DataChgClickMessage): structure.append("") # Bad fix: we have to add something for structure l-gg-ggn for i in range(len(structure_name)): - console.log("current:", i, "\ngramrel:", gramrel[i], "\nstructure:", structure[i], "\nstruc_name:", structure_name[i]) - lex = ComponentLexeme() structure[i] = structure[i].replace("Inf-", "") diff --git a/src/view/modals.py b/src/view/modals.py index c6fd6c1..0df3d73 100644 --- a/src/view/modals.py +++ b/src/view/modals.py @@ -72,6 +72,9 @@ def edit_example(example, sense): return result + divs.append(h("div.flex.five.example-component", {}, [h("div.one-fifth", {}, "Struktura:"), + h("div.three-fifth", {}, example.inner.other_attributes["structureName"])])) + for idx, component in enumerate(example.components): role_txt = component.role if component.role is not None else "none" color_class = ".example-component-" + role_txt -- 2.36.5 From 4812c18a1dde723e80e6fb5eace7ca6368623a03 Mon Sep 17 00:00:00 2001 From: LukeItUp Date: Thu, 3 Sep 2020 11:28:57 +0200 Subject: [PATCH 4/5] structure id fix --- src/lib/structure_conversions.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib/structure_conversions.py b/src/lib/structure_conversions.py index 4ba8a8e..03040ef 100644 --- a/src/lib/structure_conversions.py +++ b/src/lib/structure_conversions.py @@ -26,7 +26,7 @@ def build_structure_conversions(): vto_structure = line[1].strip().split(">")[1].split("<")[0] vto_name = line[2].strip() - vto_id = line[4].strip() + vto_id = line[6].strip() if 0 in (len(vto_name), len(vto_id)): continue @@ -41,16 +41,16 @@ def convert_structure(structure, type): for vfrom, vto_name, vto_structure, 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: + # fix for ids 106, 107, 44 which instead matched with 30 + if match and vto_id == '30' and '-s' in type: vto_name = 's0-vp-s0' - vto_id = '65' - elif match and vto_id == '64' and '-g' in type: + vto_id = '106' + elif match and vto_id == '30' and '-g' in type: vto_name = 'gg-vp-gg' - vto_id = '66' - elif match and vto_id == '64' and '-r' in type: + vto_id = '107' + elif match and vto_id == '30' and '-r' in type: vto_name = 'r-vp-r' - vto_id = '67' + vto_id = '44' if match: # we need to remove replace alias here as we want to use javascript's one -- 2.36.5 From c7a405fc46201d1854b6de0d01168ac664a10d36 Mon Sep 17 00:00:00 2001 From: LukeItUp Date: Thu, 3 Sep 2020 13:46:14 +0200 Subject: [PATCH 5/5] lock in collocations --- src/view/modals.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/view/modals.py b/src/view/modals.py index 0df3d73..7828785 100644 --- a/src/view/modals.py +++ b/src/view/modals.py @@ -64,11 +64,12 @@ def edit_example(example, sense): result.append(h("span.example-component-button.example-component-none", {"on": {"click": role_msg(idx, "none")}}, "N")) - result.extend([ - h("span.example-component-button", - {"on": {"click": message.msg(message.ExampleComponentAdd, example_original, idx)}}, "+"), - h("span.example-component-button", - {"on": {"click": message.msg(message.ExampleComponentRemove, example_original, idx)}}, "-")]) + if "-" not in example.inner.other_attributes["structureName"]: + result.extend([ + h("span.example-component-button", + {"on": {"click": message.msg(message.ExampleComponentAdd, example_original, idx)}}, "+"), + h("span.example-component-button", + {"on": {"click": message.msg(message.ExampleComponentRemove, example_original, idx)}}, "-")]) return result -- 2.36.5