From eb091fa7a9b8a1d578b56616f512123209fa2f6f Mon Sep 17 00:00:00 2001 From: kartik912 Date: Tue, 14 Oct 2025 11:50:26 +0530 Subject: [PATCH 1/9] fix the connectivity of cli commands --- pythainlp/cli/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pythainlp/cli/__init__.py b/pythainlp/cli/__init__.py index 27edb8708..92641e7d1 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 tokenize, soundex sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8") sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding="utf-8") From 5a9ee1aac35f6f8d555386f1bb427a562f3df813 Mon Sep 17 00:00:00 2001 From: kartik912 Date: Tue, 14 Oct 2025 12:13:40 +0530 Subject: [PATCH 2/9] fix the issue with ouput --- pythainlp/cli/__init__.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pythainlp/cli/__init__.py b/pythainlp/cli/__init__.py index 92641e7d1..9c9266315 100644 --- a/pythainlp/cli/__init__.py +++ b/pythainlp/cli/__init__.py @@ -36,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, + } + + # 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] + + # Call a function within the module to handle the execution. + # This "uses" the import and fixes the error. + # We assume each module has a `run` function for this to work. + 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 From 1a7b3509b5c24466fc1109447712746b04f8b24a Mon Sep 17 00:00:00 2001 From: kartik912 Date: Tue, 14 Oct 2025 12:16:48 +0530 Subject: [PATCH 3/9] fix the issue with ouput --- pythainlp/cli/__init__.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pythainlp/cli/__init__.py b/pythainlp/cli/__init__.py index 9c9266315..60a486c6c 100644 --- a/pythainlp/cli/__init__.py +++ b/pythainlp/cli/__init__.py @@ -47,10 +47,6 @@ def exit_if_empty(command: str, parser: ArgumentParser) -> None: # 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] - - # Call a function within the module to handle the execution. - # This "uses" the import and fixes the error. - # We assume each module has a `run` function for this to work. COMMAND_MAP[command].run() else: if len(sys.argv) < 2: From 3cd896cfeb9fa20837d9d691ed37bd0fa7737453 Mon Sep 17 00:00:00 2001 From: kartik912 Date: Tue, 14 Oct 2025 13:20:01 +0530 Subject: [PATCH 4/9] fixed the cli commands --- pythainlp/cli/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pythainlp/cli/__init__.py b/pythainlp/cli/__init__.py index 60a486c6c..2e9e71e1a 100644 --- a/pythainlp/cli/__init__.py +++ b/pythainlp/cli/__init__.py @@ -7,7 +7,7 @@ import io import sys from argparse import ArgumentError, ArgumentParser -from pythainlp.cli import tokenize, soundex +from pythainlp.cli import 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") @@ -42,6 +42,10 @@ def exit_if_empty(command: str, parser: ArgumentParser) -> None: COMMAND_MAP = { "tokenize": tokenize, "soundex": soundex, + "tag": tag, + "benchmark": benchmark, + "misspell": misspell, + } # Check if a command was provided and if it's one we know From 1ce4bb9c56e61639538a0631e61bbfd04a99b623 Mon Sep 17 00:00:00 2001 From: kartik912 Date: Tue, 14 Oct 2025 18:23:05 +0530 Subject: [PATCH 5/9] changed the requrements files --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 4000dc69e..6185e1e52 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ PyYAML>=5.4.1 numpy>=1.22 -pyicu>=2.3 +pandas +# pyicu>=2.3 python-crfsuite>=0.9.7 requests>=2.31 From 14e7d94aaaaad352eb2b4867f60ee8e5286b73a1 Mon Sep 17 00:00:00 2001 From: kartik912 Date: Wed, 15 Oct 2025 13:20:02 +0530 Subject: [PATCH 6/9] added pyYAML, pandas and numy in requirements in setpu.py --- requirements.txt | 5 ++--- setup.py | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 6185e1e52..44904e295 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ PyYAML>=5.4.1 numpy>=1.22 -pandas -# pyicu>=2.3 +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..d09fa4150 100644 --- a/setup.py +++ b/setup.py @@ -41,6 +41,9 @@ requirements = [ "backports.zoneinfo; python_version<'3.9'", "requests>=2.31", + "PyYAML>=5.4.1", + "pandas>=0.24", + "numpy>=1.22", "tzdata; sys_platform == 'win32'", ] From 6ae7f5892e9b82c39fc74cf6d586faf3ab0e31db Mon Sep 17 00:00:00 2001 From: kartik912 Date: Wed, 15 Oct 2025 13:24:15 +0530 Subject: [PATCH 7/9] removed the extra colde in init cli file --- pythainlp/cli/__init__.py | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/pythainlp/cli/__init__.py b/pythainlp/cli/__init__.py index 2e9e71e1a..e2ef0a2b2 100644 --- a/pythainlp/cli/__init__.py +++ b/pythainlp/cli/__init__.py @@ -7,7 +7,7 @@ import io import sys from argparse import ArgumentError, ArgumentParser -from pythainlp.cli import tokenize, soundex, tag, benchmark, misspell +# from pythainlp.cli import 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") @@ -37,23 +37,4 @@ def exit_if_empty(command: str, parser: ArgumentParser) -> None: 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, - - } - - # 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 +from pythainlp.cli import tokenize, soundex, tag, benchmark, misspell \ No newline at end of file From 9621c8d05701e6322b8ef4d44374964697fc8393 Mon Sep 17 00:00:00 2001 From: kartik912 Date: Wed, 15 Oct 2025 13:44:11 +0530 Subject: [PATCH 8/9] added constant for requirements and revert back the changes for init cli file --- pythainlp/cli/__init__.py | 23 +++++++++++++++++++++-- setup.py | 36 ++++++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/pythainlp/cli/__init__.py b/pythainlp/cli/__init__.py index e2ef0a2b2..2e9e71e1a 100644 --- a/pythainlp/cli/__init__.py +++ b/pythainlp/cli/__init__.py @@ -7,7 +7,7 @@ import io import sys from argparse import ArgumentError, ArgumentParser -# from pythainlp.cli import tokenize, soundex, tag, benchmark, misspell +from pythainlp.cli import 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") @@ -37,4 +37,23 @@ def exit_if_empty(command: str, parser: ArgumentParser) -> None: parser.print_help() raise ArgumentError(None, "No command provided.") -from pythainlp.cli import tokenize, soundex, tag, benchmark, misspell \ No newline at end of file +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, + + } + + # 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/setup.py b/setup.py index d09fa4150..711899f30 100644 --- a/setup.py +++ b/setup.py @@ -10,6 +10,14 @@ from setuptools import find_packages, setup +""" +constant for frequently use values +""" + +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,16 +49,16 @@ requirements = [ "backports.zoneinfo; python_version<'3.9'", "requests>=2.31", - "PyYAML>=5.4.1", - "pandas>=0.24", - "numpy>=1.22", + 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", @@ -69,10 +77,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"], @@ -80,8 +88,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"', @@ -97,7 +105,7 @@ ], "wangchanberta": ["sentencepiece>=0.1.91", "transformers>=4.6.0"], "wangchanglm": [ - "pandas>=0.24", + PANDAS, "sentencepiece>=0.1.91", "transformers>=4.6.0", ], @@ -108,15 +116,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", @@ -129,10 +137,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", From e9babd35d0a844894d16fad8ace2a46c92f0ab42 Mon Sep 17 00:00:00 2001 From: kartik912 Date: Wed, 15 Oct 2025 14:38:05 +0530 Subject: [PATCH 9/9] imported data library --- pythainlp/cli/__init__.py | 4 ++-- setup.py | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/pythainlp/cli/__init__.py b/pythainlp/cli/__init__.py index 2e9e71e1a..dbb0c0dd0 100644 --- a/pythainlp/cli/__init__.py +++ b/pythainlp/cli/__init__.py @@ -7,7 +7,7 @@ import io import sys from argparse import ArgumentError, ArgumentParser -from pythainlp.cli import tokenize, soundex, tag, benchmark, misspell +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") @@ -45,7 +45,7 @@ def exit_if_empty(command: str, parser: ArgumentParser) -> None: "tag": tag, "benchmark": benchmark, "misspell": misspell, - + "data": data, } # Check if a command was provided and if it's one we know diff --git a/setup.py b/setup.py index 711899f30..ce8092e23 100644 --- a/setup.py +++ b/setup.py @@ -10,10 +10,6 @@ from setuptools import find_packages, setup -""" -constant for frequently use values -""" - PYYAML = "PyYAML>=5.4.1" PANDAS = "pandas>=0.24" NUMPY = "numpy>=1.22"