Feature#1405 collocation structure

This commit is contained in:
Luka Kavčič 2020-07-17 10:50:12 +02:00
parent b010414bfe
commit aca8093ab3
3 changed files with 17 additions and 6 deletions

View File

@ -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

View File

@ -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', '/'

View File

@ -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}