Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pythainlp/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 18 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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",
Expand All @@ -66,19 +73,19 @@
"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"],
"spell": ["phunspell>=0.1.6", "symspellpy>=6.7.6"],
"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"',
Expand All @@ -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",
],
Expand All @@ -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",
Expand All @@ -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",
Expand Down
Loading