From aca8093ab31fd4c19a8335cdb3f13864196abbcb Mon Sep 17 00:00:00 2001 From: LukeItUp Date: Fri, 17 Jul 2020 10:50:12 +0200 Subject: [PATCH] Feature#1405 collocation structure --- build/Makefile | 2 +- src/lib/structure_conversions.py | 17 ++++++++++++++--- src/message/ske_messages.py | 4 ++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/build/Makefile b/build/Makefile index 5113996..9fb0d7a 100644 --- a/build/Makefile +++ b/build/Makefile @@ -31,7 +31,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/lib/structure_conversions.py b/src/lib/structure_conversions.py index 5e408fc..2dbfec8 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 which matched instead with 64 + if match and vto_id == '64' and '-g' in type: + vto_name = 'gg-vp-gg' + vto_id = '66' + elif match and vto_id == '64' and '-s' in type: + vto_name = 's0-vp-s0' + vto_id = '65' + 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") - + + if vto_id == '64': + console.log(structure) + 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 6900cdf..9d03c9b 100644 --- a/src/message/ske_messages.py +++ b/src/message/ske_messages.py @@ -58,7 +58,7 @@ class SkeCollocation: def __init__(self, data): self.word = data.word self.frequency = data.count - self.structure_name, self.structure_id = convert_structure(data.gramrel) + self.structure_name, self.structure_id = convert_structure(data.gramrel, data.filterwords) self.other = {"score": data.score, "cm": data.cm} @@ -71,7 +71,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: