commit e1740ef14b1d1aa18398692e9aa7850f75d97bfd Merge: 943957e d697e67 Author: vaydheesh Date: Wed Jun 12 19:51:33 2019 +0000 Merge branch 'master' into swig_wrapper diff --combined apertium/analysis/__init__.py index 95f88ab,a47d8e0..85c3e1a --- a/apertium/analysis/__init__.py +++ b/apertium/analysis/__init__.py @@@ -1,11 -1,9 +1,10 @@@ +import os - from streamparser import parse, LexicalUnit # noqa: F401 + from typing import Dict, List - import apertium - from apertium.utils import to_alpha3_code, execute, parse_mode_file + from streamparser import LexicalUnit, parse - if False: - from typing import List, Union, Dict # noqa: F401 + import apertium + from apertium.utils import execute, parse_mode_file, to_alpha3_code class Analyzer: @@@ -15,7 -13,7 +14,7 @@@ lang (str) """ - def __init__(self, lang): # type: (Analyzer, str) -> None + def __init__(self, lang: str) -> None: """ Args: lang (str) @@@ -34,12 -32,10 +33,12 @@@ """ if self.lang not in self.analyzer_cmds: mode_path, mode = apertium.analyzers[self.lang] - self.analyzer_cmds[self.lang] = parse_mode_file(mode_path + '/modes/' + mode + '.mode') + abs_mode_path = os.path.join(mode_path, 'modes', '{}.mode'.format(mode)) + self.analyzer_cmds[self.lang] = parse_mode_file(abs_mode_path) return self.analyzer_cmds[self.lang] - def _postproc_text(self, result): # type: (Analyzer, str) -> List[LexicalUnit] + @staticmethod + def _postproc_text(result): # type: (str) -> List[LexicalUnit] """ Postprocesses the input @@@ -63,9 -59,8 +62,9 @@@ Returns: List[LexicalUnit] """ - apertium_des = execute(in_text, [['apertium-des{}'.format(formatting), '-n']]) - result = execute(apertium_des, self._get_commands()) + self._get_commands() + self.analyzer_cmds[self.lang].insert(0, ['apertium-des{}'.format(formatting), '-n']) + result = execute(in_text, self.analyzer_cmds[self.lang]) return self._postproc_text(result) diff --combined apertium/utils.py index 3a479e3,d05e802..6ef8ff1 --- a/apertium/utils.py +++ b/apertium/utils.py @@@ -1,17 -1,15 +1,15 @@@ - import subprocess import re - - if False: - from typing import List, Dict, Tuple, Union # noqa: F401 + import subprocess + from typing import List import apertium # noqa: F401 - from apertium.iso639 import iso_639_codes # noqa: F401 - from apertium import lttoolbox # noqa: F401 + from apertium.iso639 import iso_639_codes - ++from apertium import lttoolbox iso639_codes_inverse = {v: k for k, v in iso_639_codes.items()} - def to_alpha3_code(code): # type: (str) -> str + def to_alpha3_code(code: str) -> str: """ Args: code (str) @@@ -26,7 -24,7 +24,7 @@@ return iso639_codes_inverse[code] if code in iso639_codes_inverse else code - def execute(inp, commands): # type: (str, List[List[str]]) -> str + def execute(inp: str, commands: List[List[str]]) -> str: """ Args: inp (str) @@@ -38,13 -36,6 +36,13 @@@ procs = [] end = inp.encode() for i, command in enumerate(commands): + if 'lt-proc' and '-w' in command: + arg_index = command.index('-w') + automorf_path = command[-1] + ltp = lttoolbox.LtProc(end.decode(), command[arg_index], automorf_path) + end = ltp.execute() + continue + procs.append( subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE), ) @@@ -52,7 -43,7 +50,7 @@@ return end.decode() - def parse_mode_file(mode_path): # type: (str) -> List[List[str]] + def parse_mode_file(mode_path: str) -> List[List[str]]: """ Args: mode_path (str)