diff --git a/pythainlp/cli/__init__.py b/pythainlp/cli/__init__.py index 27edb8708..dbb0c0dd0 100644 --- a/pythainlp/cli/__init__.py +++ b/pythainlp/cli/__init__.py @@ -7,6 +7,7 @@ import io import sys from argparse import ArgumentError, ArgumentParser +from pythainlp.cli import data, tokenize, soundex, tag, benchmark, misspell sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8") sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding="utf-8") @@ -35,3 +36,24 @@ def exit_if_empty(command: str, parser: ArgumentParser) -> None: if parser: parser.print_help() raise ArgumentError(None, "No command provided.") + +if __name__ == "__main__": + # Create a simple mapping from command name to the imported module + COMMAND_MAP = { + "tokenize": tokenize, + "soundex": soundex, + "tag": tag, + "benchmark": benchmark, + "misspell": misspell, + "data": data, + } + + # Check if a command was provided and if it's one we know + if len(sys.argv) > 1 and sys.argv[1] in COMMAND_MAP: + command = sys.argv[1] + COMMAND_MAP[command].run() + else: + if len(sys.argv) < 2: + print(f"Error: No command provided. Choose one of: {list(COMMAND_MAP.keys())}", file=sys.stderr) + else: + print(f"Error: Unknown command '{sys.argv[1]}'", file=sys.stderr) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 4000dc69e..44904e295 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ PyYAML>=5.4.1 numpy>=1.22 pyicu>=2.3 python-crfsuite>=0.9.7 -requests>=2.31 +requests>=2.31 \ No newline at end of file diff --git a/setup.py b/setup.py index 171471080..ce8092e23 100644 --- a/setup.py +++ b/setup.py @@ -10,6 +10,10 @@ from setuptools import find_packages, setup +PYYAML = "PyYAML>=5.4.1" +PANDAS = "pandas>=0.24" +NUMPY = "numpy>=1.22" + LONG_DESC = """ ![PyThaiNLP Logo](https://avatars0.githubusercontent.com/u/32934255?s=200&v=4) @@ -41,13 +45,16 @@ requirements = [ "backports.zoneinfo; python_version<'3.9'", "requests>=2.31", + PYYAML, + PANDAS, + NUMPY, "tzdata; sys_platform == 'win32'", ] extras = { "abbreviation": ["khamyo>=0.2.0"], "attacut": ["attacut>=1.0.6"], - "benchmarks": ["PyYAML>=5.4.1", "numpy>=1.22", "pandas>=0.24"], + "benchmarks": [PYYAML, NUMPY, PANDAS], "coreference_resolution": [ "fastcoref>=2.1.5", "spacy>=3.0", @@ -66,10 +73,10 @@ "generate": ["fastai<2.0"], "icu": ["pyicu>=2.3"], "ipa": ["epitran>=1.1"], - "ml": ["numpy>=1.22", "torch>=1.0.0"], + "ml": [NUMPY, "torch>=1.0.0"], "mt5": ["sentencepiece>=0.1.91", "transformers>=4.6.0"], "nlpo3": ["nlpo3>=1.3.1"], - "onnx": ["numpy>=1.22", "onnxruntime>=1.10.0", "sentencepiece>=0.1.91"], + "onnx": [NUMPY, "onnxruntime>=1.10.0", "sentencepiece>=0.1.91"], "oskut": ["oskut>=1.3"], "sefr_cut": ["sefr_cut>=1.1"], "spacy_thai": ["spacy_thai>=0.7.1"], @@ -77,8 +84,8 @@ "ssg": ["ssg>=0.0.8"], "textaugment": ["bpemb", "gensim>=4.0.0"], "thai_nner": ["thai_nner"], - "thai2fit": ["emoji>=0.5.1", "gensim>=4.0.0", "numpy>=1.22"], - "thai2rom": ["numpy>=1.22", "torch>=1.0.0"], + "thai2fit": ["emoji>=0.5.1", "gensim>=4.0.0", NUMPY], + "thai2rom": [NUMPY, "torch>=1.0.0"], "translate": [ 'fairseq>=0.10.0,<0.13;python_version<"3.11"', 'fairseq-fixed==0.12.3.1,<0.13;python_version>="3.11"', @@ -94,7 +101,7 @@ ], "wangchanberta": ["sentencepiece>=0.1.91", "transformers>=4.6.0"], "wangchanglm": [ - "pandas>=0.24", + PANDAS, "sentencepiece>=0.1.91", "transformers>=4.6.0", ], @@ -105,15 +112,15 @@ "wunsen": ["wunsen>=0.0.1"], # Compact dependencies, this one matches requirements.txt "compact": [ - "PyYAML>=5.4.1", + PYYAML, "nlpo3>=1.3.1", - "numpy>=1.22", + NUMPY, "pyicu>=2.3", "python-crfsuite>=0.9.7", ], # Full dependencies "full": [ - "PyYAML>=5.4.1", + PYYAML, "attacut>=1.0.4", "bpemb>=0.3.2", "emoji>=0.5.1", @@ -126,10 +133,10 @@ "khamyo>=0.2.0", "nlpo3>=1.3.1", "nltk>=3.3", - "numpy>=1.22", + NUMPY, "onnxruntime>=1.10.0", "oskut>=1.3", - "pandas>=0.24", + PANDAS, "panphon>=0.20.0", "phunspell>=0.1.6", "pyicu>=2.3",