This repository has been archived by the owner on Feb 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.py
62 lines (48 loc) · 1.52 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import argparse
import importlib
from pathlib import Path
from typing import List
from jpype import shutdownJVM, startJVM
from examples import JVM_KWARGS
def get_runnable_modules() -> List[str]:
"""
Returns a list of scripts which implement the run function.
Returns:
List[str]: List of script names in 'module.submodule.script' format.
"""
runnable_modules: List[str] = []
for script in Path('examples').glob('**/*.py'):
if script.name == '__init__.py':
continue
module_name: str = (
f'{script.parents[0].name}.{script.name.split(".")[0]}'
)
if hasattr(importlib.import_module(f'examples.{module_name}'), 'run'):
runnable_modules.append(module_name)
return runnable_modules
if __name__ == '__main__':
startJVM(**JVM_KWARGS)
parser = argparse.ArgumentParser(
description=(
'Run a Zemberek example. Example usage: python -m main'
' morphology.word_analysis kelime'
)
)
parser.add_argument(
'example',
type=str,
help='The run() function from the chosen script will be invoked.',
choices=get_runnable_modules(),
)
parser.add_argument(
'args',
type=str,
default=[],
nargs='*',
help='Arguments to pass to the run function.',
)
args = parser.parse_args()
example = importlib.import_module(f'examples.{args.example}')
print(example.run.__doc__)
example.run(*args.args)
shutdownJVM()