Skip to content

Commit 9061d86

Browse files
updated: wrapper calls for getopts
1 parent c7089cc commit 9061d86

File tree

2 files changed

+43
-13
lines changed

2 files changed

+43
-13
lines changed

apertium/utils.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def deformatter(text: str) -> str:
4545
"""
4646
escape_chars = b'[]{}?^$@\\'
4747
_special_chars_map = {i: '\\' + chr(i) for i in escape_chars}
48-
return '{}.[][\n]'.format(text.translate(_special_chars_map))
48+
return '{}[][\n]'.format(text.translate(_special_chars_map))
4949

5050

5151
def execute_pipeline(inp: str, commands: List[List[str]]) -> str:
@@ -82,23 +82,29 @@ def execute_pipeline(inp: str, commands: List[List[str]]) -> str:
8282
fst = lttoolbox.FST(dictionary_path)
8383
if not fst.valid():
8484
raise ValueError('FST Invalid')
85-
fst.lt_proc(arg, input_file_name, output_file_name)
85+
lt_proc_command = command[:-1]
86+
fst.lt_proc(len(lt_proc_command), lt_proc_command, input_file.name, output_file.name)
8687
elif 'lrx-proc' == command[0]:
8788
dictionary_path = command[-1]
8889
lextools.LtLocale.tryToSetLocale()
8990
lrx = lextools.LRXProc(dictionary_path)
90-
lrx.lrx_proc(arg, input_file.name, output_file.name)
91+
lrx_proc_command = command[:-1]
92+
lrx.lrx_proc(len(lrx_proc_command), lrx_proc_command, input_file.name, output_file.name)
9193
elif 'apertium-transfer' == command[0]:
92-
transfer = apertium_core.ApertiumTransfer(command[2], command[3])
93-
transfer.transfer_text(arg, input_file.name, output_file.name)
94+
transfer = apertium_core.ApertiumTransfer(command[-2], command[-1])
95+
transfer_command = command[:-2]
96+
transfer.transfer_text(len(transfer_command), transfer_command, input_file.name, output_file.name)
9497
elif 'apertium-interchunk' == command[0]:
95-
interchunk = apertium_core.ApertiumInterchunk(command[1], command[2])
96-
interchunk.interchunk_text(arg, input_file.name, output_file.name)
98+
interchunk = apertium_core.ApertiumInterchunk(command[-2], command[-1])
99+
interchunk_command = command[:-2]
100+
interchunk.interchunk_text(len(interchunk_command), interchunk_command, input_file.name, output_file.name)
97101
elif 'apertium-postchunk' == command[0]:
98-
postchunk = apertium_core.ApertiumPostchunk(command[1], command[2])
99-
postchunk.postchunk_text(arg, input_file.name, output_file.name)
102+
postchunk = apertium_core.ApertiumPostchunk(command[-2], command[-1])
103+
postchunk_command = command[:-2]
104+
postchunk.postchunk_text(len(postchunk_command), postchunk_command, input_file.name, output_file.name)
100105
elif 'apertium-pretransfer' == command[0]:
101-
apertium_core.pretransfer(arg, input_file.name, output_file.name)
106+
command = ['apertium-pretransfer', '']
107+
apertium_core.pretransfer(len(command), command, input_file.name, output_file.name)
102108
elif 'apertium-tagger' == command[0]:
103109
command += [input_file.name, output_file.name]
104110
apertium_core.ApertiumTagger(len(command), command)
@@ -115,8 +121,8 @@ def execute_pipeline(inp: str, commands: List[List[str]]) -> str:
115121
end = output_file.read()
116122
output_file.close()
117123

118-
os.remove(input_file_name)
119-
os.remove(output_file_name)
124+
os.remove(input_file.name)
125+
os.remove(output_file.name)
120126
if not wrappers_available or not used_wrapper:
121127
apertium.logger.warning('Calling subprocess %s', command[0])
122128
proc = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE)

build-swig-wrapper.sh

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
11
#!/usr/bin/env bash
22
set -xe
33

4-
sudo apt-get install -y cmake libboost-dev libicu-dev swig build-essential python3-setuptools
4+
sudo apt-get install -y swig build-essential python3-setuptools
5+
6+
git clone --depth 1 -b wrapper_getopt https://github.com/apertium/apertium-lex-tools.git
7+
pushd apertium-lex-tools
8+
./autogen.sh --enable-python-bindings
9+
cd python
10+
make -j2
11+
python3 setup.py install
12+
popd
13+
14+
git clone --depth 1 -b wrapper_getopt https://github.com/apertium/apertium.git apertium-core
15+
pushd apertium-core
16+
./autogen.sh --enable-python-bindings
17+
cd python
18+
make -j2
19+
python3 setup.py install
20+
popd
21+
22+
git clone --depth 1 -b wrapper_getopt https://github.com/apertium/lttoolbox.git
23+
pushd lttoolbox
24+
./autogen.sh --enable-python-bindings
25+
cd python
26+
make -j2
27+
python3 setup.py install
28+
popd
529

630
git clone -b swig --depth 1 https://github.com/Vaydheesh/cg3.git
731
pushd cg3

0 commit comments

Comments
 (0)