Skip to content

Commit

Permalink
Merge 76a8664 into 8506f5e
Browse files Browse the repository at this point in the history
  • Loading branch information
singh-lokendra committed Aug 1, 2019
2 parents 8506f5e + 76a8664 commit f938af7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
29 changes: 14 additions & 15 deletions apertium/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,37 +56,36 @@ def execute_pipeline(inp: str, commands: List[List[str]]) -> str:
input_file_name, output_file_name = input_file.name, output_file.name

arg = command[1][1] if len(command) >= 3 else ''
path = command[-1]
text = end.decode()
input_file.write(text)
input_file.close()

if 'lt-proc' == command[0]:
dictionary_path = command[-1]
lttoolbox.LtLocale.tryToSetLocale()
fst = lttoolbox.FST()
fst = lttoolbox.FST(dictionary_path)
if not fst.valid():
raise ValueError('FST Invalid')
fst = lttoolbox.FST()
fst.lt_proc(arg, path, input_file_name, output_file_name)
fst.lt_proc(arg, input_file_name, output_file_name)
elif 'lrx-proc' == command[0]:
dictionary_path = command[-1]
lextools.LtLocale.tryToSetLocale()
lrx = lextools.LRX()
lrx.lrx_proc(arg, path, input_file.name, output_file.name)
lrx = lextools.LRXProc(dictionary_path)
lrx.lrx_proc(arg, input_file.name, output_file.name)
elif 'apertium-transfer' == command[0]:
obj = apertium_core.apertium()
obj.transfer_text(arg, command[2], command[3], input_file.name, output_file.name)
obj = apertium_core.ApertiumTransfer(command[2], command[3])
obj.transfer_text(arg, input_file.name, output_file.name)
elif 'apertium-interchunk' == command[0]:
obj = apertium_core.apertium()
obj.interchunk_text(arg, command[1], command[2], input_file.name, output_file.name)
obj = apertium_core.ApertiumInterchunk(command[1], command[2])
obj.interchunk_text(arg, input_file.name, output_file.name)
elif 'apertium-postchunk' == command[0]:
obj = apertium_core.apertium()
obj.postchunk_text(arg, command[1], command[2], input_file.name, output_file.name)
obj = apertium_core.ApertiumPostchunk(command[1], command[2])
obj.postchunk_text(arg, input_file.name, output_file.name)
elif 'apertium-pretransfer' == command[0]:
obj = apertium_core.apertium()
obj.pretransfer(arg, input_file.name, output_file.name)
apertium_core.pretransfer(arg, input_file.name, output_file.name)
elif 'apertium-tagger' == command[0]:
command += [input_file.name, output_file.name]
apertium_core.tagger(len(command), command)
apertium_core.ApertiumTagger(len(command), command)
else:
used_wrapper = False

Expand Down
10 changes: 9 additions & 1 deletion build-swig-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@ make -j2
python3 setup.py install
popd

git clone --depth 1 https://github.com/apertium/apertium.git apertium-core
git clone --depth 1 -b wrapper_optimise 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
cd python
make -j2
python3 setup.py install
popd
21 changes: 21 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import importlib.util
import os
import platform
import shutil
import sys
import unittest

Expand Down Expand Up @@ -69,6 +72,24 @@ def test_uninstalled_mode(self):
apertium.generate('spa', 'cat<n><pl>')


class TestInstallation(unittest.TestCase):
def test_apertium_base(self):
apertium.installer.install_apertium()
self.assertIsNotNone(shutil.which('lt-proc'), 'apertium binaries not installed')

def test_install_module(self):
language = 'kir'
apertium.installer.install_module(language)
importlib.reload(apertium)
self.assertIn(language, apertium.analyzers, 'apetium.install_module not working')

def test_install_wrapper(self):
apertium.installer.install_wrapper('python3-lttoolbox')
if platform.system() == 'Linux':
sys.path.append('/usr/lib/python3/dist-packages')
self.assertIsNotNone(importlib.util.find_spec('lttoolbox'), 'Wrapper not installed')


class TestTranslate(unittest.TestCase):
def test_translator_en_spa(self):
translator = apertium.Translator('eng', 'spa')
Expand Down

0 comments on commit f938af7

Please sign in to comment.