Skip to content

Commit a14b4b5

Browse files
authored
fix the connectivity of cli commands (#1154)
* fix the connectivity of cli commands * fix the issue with ouput * fix the issue with ouput * fixed the cli commands * changed the requrements files * added pyYAML, pandas and numy in requirements in setpu.py * removed the extra colde in init cli file * added constant for requirements and revert back the changes for init cli file * imported data library
1 parent 999e2a6 commit a14b4b5

File tree

3 files changed

+41
-12
lines changed

3 files changed

+41
-12
lines changed

pythainlp/cli/__init__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io
88
import sys
99
from argparse import ArgumentError, ArgumentParser
10+
from pythainlp.cli import data, tokenize, soundex, tag, benchmark, misspell
1011

1112
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
1213
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding="utf-8")
@@ -35,3 +36,24 @@ def exit_if_empty(command: str, parser: ArgumentParser) -> None:
3536
if parser:
3637
parser.print_help()
3738
raise ArgumentError(None, "No command provided.")
39+
40+
if __name__ == "__main__":
41+
# Create a simple mapping from command name to the imported module
42+
COMMAND_MAP = {
43+
"tokenize": tokenize,
44+
"soundex": soundex,
45+
"tag": tag,
46+
"benchmark": benchmark,
47+
"misspell": misspell,
48+
"data": data,
49+
}
50+
51+
# Check if a command was provided and if it's one we know
52+
if len(sys.argv) > 1 and sys.argv[1] in COMMAND_MAP:
53+
command = sys.argv[1]
54+
COMMAND_MAP[command].run()
55+
else:
56+
if len(sys.argv) < 2:
57+
print(f"Error: No command provided. Choose one of: {list(COMMAND_MAP.keys())}", file=sys.stderr)
58+
else:
59+
print(f"Error: Unknown command '{sys.argv[1]}'", file=sys.stderr)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ PyYAML>=5.4.1
22
numpy>=1.22
33
pyicu>=2.3
44
python-crfsuite>=0.9.7
5-
requests>=2.31
5+
requests>=2.31

setup.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
from setuptools import find_packages, setup
1212

13+
PYYAML = "PyYAML>=5.4.1"
14+
PANDAS = "pandas>=0.24"
15+
NUMPY = "numpy>=1.22"
16+
1317
LONG_DESC = """
1418
![PyThaiNLP Logo](https://avatars0.githubusercontent.com/u/32934255?s=200&v=4)
1519
@@ -41,13 +45,16 @@
4145
requirements = [
4246
"backports.zoneinfo; python_version<'3.9'",
4347
"requests>=2.31",
48+
PYYAML,
49+
PANDAS,
50+
NUMPY,
4451
"tzdata; sys_platform == 'win32'",
4552
]
4653

4754
extras = {
4855
"abbreviation": ["khamyo>=0.2.0"],
4956
"attacut": ["attacut>=1.0.6"],
50-
"benchmarks": ["PyYAML>=5.4.1", "numpy>=1.22", "pandas>=0.24"],
57+
"benchmarks": [PYYAML, NUMPY, PANDAS],
5158
"coreference_resolution": [
5259
"fastcoref>=2.1.5",
5360
"spacy>=3.0",
@@ -66,19 +73,19 @@
6673
"generate": ["fastai<2.0"],
6774
"icu": ["pyicu>=2.3"],
6875
"ipa": ["epitran>=1.1"],
69-
"ml": ["numpy>=1.22", "torch>=1.0.0"],
76+
"ml": [NUMPY, "torch>=1.0.0"],
7077
"mt5": ["sentencepiece>=0.1.91", "transformers>=4.6.0"],
7178
"nlpo3": ["nlpo3>=1.3.1"],
72-
"onnx": ["numpy>=1.22", "onnxruntime>=1.10.0", "sentencepiece>=0.1.91"],
79+
"onnx": [NUMPY, "onnxruntime>=1.10.0", "sentencepiece>=0.1.91"],
7380
"oskut": ["oskut>=1.3"],
7481
"sefr_cut": ["sefr_cut>=1.1"],
7582
"spacy_thai": ["spacy_thai>=0.7.1"],
7683
"spell": ["phunspell>=0.1.6", "symspellpy>=6.7.6"],
7784
"ssg": ["ssg>=0.0.8"],
7885
"textaugment": ["bpemb", "gensim>=4.0.0"],
7986
"thai_nner": ["thai_nner"],
80-
"thai2fit": ["emoji>=0.5.1", "gensim>=4.0.0", "numpy>=1.22"],
81-
"thai2rom": ["numpy>=1.22", "torch>=1.0.0"],
87+
"thai2fit": ["emoji>=0.5.1", "gensim>=4.0.0", NUMPY],
88+
"thai2rom": [NUMPY, "torch>=1.0.0"],
8289
"translate": [
8390
'fairseq>=0.10.0,<0.13;python_version<"3.11"',
8491
'fairseq-fixed==0.12.3.1,<0.13;python_version>="3.11"',
@@ -94,7 +101,7 @@
94101
],
95102
"wangchanberta": ["sentencepiece>=0.1.91", "transformers>=4.6.0"],
96103
"wangchanglm": [
97-
"pandas>=0.24",
104+
PANDAS,
98105
"sentencepiece>=0.1.91",
99106
"transformers>=4.6.0",
100107
],
@@ -105,15 +112,15 @@
105112
"wunsen": ["wunsen>=0.0.1"],
106113
# Compact dependencies, this one matches requirements.txt
107114
"compact": [
108-
"PyYAML>=5.4.1",
115+
PYYAML,
109116
"nlpo3>=1.3.1",
110-
"numpy>=1.22",
117+
NUMPY,
111118
"pyicu>=2.3",
112119
"python-crfsuite>=0.9.7",
113120
],
114121
# Full dependencies
115122
"full": [
116-
"PyYAML>=5.4.1",
123+
PYYAML,
117124
"attacut>=1.0.4",
118125
"bpemb>=0.3.2",
119126
"emoji>=0.5.1",
@@ -126,10 +133,10 @@
126133
"khamyo>=0.2.0",
127134
"nlpo3>=1.3.1",
128135
"nltk>=3.3",
129-
"numpy>=1.22",
136+
NUMPY,
130137
"onnxruntime>=1.10.0",
131138
"oskut>=1.3",
132-
"pandas>=0.24",
139+
PANDAS,
133140
"panphon>=0.20.0",
134141
"phunspell>=0.1.6",
135142
"pyicu>=2.3",

0 commit comments

Comments
 (0)