commit ef97bae8a160ffb068bfc8c958622dc4c8b11dc7 Author: Lokendra Singh Date: Sun Aug 11 22:36:28 2019 +0530 Add cg-proc wrapper (#58) * added: cg-proc wrapper stop building wrappers on travis, debian packages up to date * improved object names diff --git a/apertium/utils.py b/apertium/utils.py index 30176d4..3c2c52c 100644 --- a/apertium/utils.py +++ b/apertium/utils.py @@ -12,6 +12,7 @@ try: import apertium_core import lextools import lttoolbox + import constraint_grammar wrappers_available = True except ImportError: wrappers_available = False @@ -73,19 +74,24 @@ def execute_pipeline(inp: str, commands: List[List[str]]) -> str: lrx = lextools.LRXProc(dictionary_path) lrx.lrx_proc(arg, input_file.name, output_file.name) elif 'apertium-transfer' == command[0]: - obj = apertium_core.ApertiumTransfer(command[2], command[3]) - obj.transfer_text(arg, input_file.name, output_file.name) + transfer = apertium_core.ApertiumTransfer(command[2], command[3]) + transfer.transfer_text(arg, input_file.name, output_file.name) elif 'apertium-interchunk' == command[0]: - obj = apertium_core.ApertiumInterchunk(command[1], command[2]) - obj.interchunk_text(arg, input_file.name, output_file.name) + interchunk = apertium_core.ApertiumInterchunk(command[1], command[2]) + interchunk.interchunk_text(arg, input_file.name, output_file.name) elif 'apertium-postchunk' == command[0]: - obj = apertium_core.ApertiumPostchunk(command[1], command[2]) - obj.postchunk_text(arg, input_file.name, output_file.name) + postchunk = apertium_core.ApertiumPostchunk(command[1], command[2]) + postchunk.postchunk_text(arg, input_file.name, output_file.name) elif 'apertium-pretransfer' == command[0]: apertium_core.pretransfer(arg, input_file.name, output_file.name) elif 'apertium-tagger' == command[0]: command += [input_file.name, output_file.name] apertium_core.ApertiumTagger(len(command), command) + elif 'cg-proc' == command[0]: + dictionary_path = command[-1] + cg = constraint_grammar.CGProc(dictionary_path) + cg_proc_command = command[:-1] + cg.cg_proc(len(cg_proc_command), cg_proc_command, input_file.name, output_file.name) else: used_wrapper = False diff --git a/build-swig-wrapper.sh b/build-swig-wrapper.sh index 3da1ccf..edab6fc 100755 --- a/build-swig-wrapper.sh +++ b/build-swig-wrapper.sh @@ -1,27 +1,11 @@ #!/usr/bin/env bash set -xe -sudo apt-get install -y swig build-essential python3-setuptools +sudo apt-get install -y cmake libboost-dev libicu-dev swig build-essential python3-setuptools -git clone --depth 1 https://github.com/apertium/apertium-lex-tools.git -pushd apertium-lex-tools -./autogen.sh --enable-python-bindings -cd python -make -j2 -python3 setup.py install -popd - -git clone --depth 1 https://github.com/apertium/apertium.git apertium-core -pushd apertium-core -./autogen.sh --enable-python-bindings -cd python -make -j2 -python3 setup.py install -popd - -git clone --depth 1 https://github.com/apertium/lttoolbox.git -pushd lttoolbox -./autogen.sh --enable-python-bindings +git clone -b swig --depth 1 https://github.com/Vaydheesh/cg3.git +pushd cg3 +cmake -DENABLE_PYTHON_BINDINGS:BOOL=ON . cd python make -j2 python3 setup.py install diff --git a/tests/__init__.py b/tests/__init__.py index 01e06b7..46f7b54 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -107,3 +107,9 @@ class TestTranslate(unittest.TestCase): def test_en_spa(self): translated = apertium.translate('eng', 'spa', 'cats') self.assertEqual(translated, 'Gatos') + + def test_kaz_tat(self): + apertium.installer.install_module('kaz-tat') + importlib.reload(apertium) + translated = apertium.translate('kaz', 'tat', 'мысық') + self.assertEqual(translated, 'мәче')