iapp-ai 2.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. iapp_ai/__init__.py +9 -0
  2. iapp_ai/_core_compat.py +55 -0
  3. iapp_ai/module_api.py +1202 -0
  4. iapp_ai/nlp/__init__.py +18 -0
  5. iapp_ai/nlp/cli.py +43 -0
  6. iapp_ai/nlp/corpus/__init__.py +5 -0
  7. iapp_ai/nlp/corpus/common.py +89 -0
  8. iapp_ai/nlp/data/latte/charclass.npz +0 -0
  9. iapp_ai/nlp/data/latte/lexicon.txt.gz +0 -0
  10. iapp_ai/nlp/data/latte/manifest.json +47 -0
  11. iapp_ai/nlp/data/latte/model.int8.onnx +0 -0
  12. iapp_ai/nlp/data/stopwords_th.txt +1030 -0
  13. iapp_ai/nlp/data/thailand_provinces_th.csv +77 -0
  14. iapp_ai/nlp/data/words_th.txt +62107 -0
  15. iapp_ai/nlp/py.typed +0 -0
  16. iapp_ai/nlp/tag/__init__.py +5 -0
  17. iapp_ai/nlp/tag/locations.py +18 -0
  18. iapp_ai/nlp/tokenizer/__init__.py +12 -0
  19. iapp_ai/nlp/tokenizer/core.py +245 -0
  20. iapp_ai/nlp/tokenizer/latte.py +429 -0
  21. iapp_ai/nlp/tokenizer/token.py +12 -0
  22. iapp_ai/nlp/util/__init__.py +37 -0
  23. iapp_ai/nlp/util/_calendar.py +17 -0
  24. iapp_ai/nlp/util/date.py +377 -0
  25. iapp_ai/nlp/util/digitconv.py +232 -0
  26. iapp_ai/nlp/util/normalizer.py +92 -0
  27. iapp_ai/nlp/util/numtoword.py +235 -0
  28. iapp_ai/nlp/util/strftime.py +380 -0
  29. iapp_ai/py.typed +0 -0
  30. iapp_ai-2.0.0.dist-info/METADATA +159 -0
  31. iapp_ai-2.0.0.dist-info/RECORD +38 -0
  32. iapp_ai-2.0.0.dist-info/WHEEL +4 -0
  33. iapp_ai-2.0.0.dist-info/entry_points.txt +2 -0
  34. iapp_ai-2.0.0.dist-info/licenses/LICENSE +21 -0
  35. iapp_ai-2.0.0.dist-info/licenses/LICENSE-APACHE +201 -0
  36. iapp_ai-2.0.0.dist-info/licenses/LICENSES/CC-BY-SA-4.0.txt +428 -0
  37. iapp_ai-2.0.0.dist-info/licenses/LICENSES/Unicode-DFS-2016.txt +31 -0
  38. iapp_ai-2.0.0.dist-info/licenses/NOTICE +46 -0
iapp_ai/__init__.py ADDED
@@ -0,0 +1,9 @@
1
+ """Top-level package for iApp AI API pip package."""
2
+
3
+ __author__ = """Kobkrit Viriyayudhakorn"""
4
+ __email__ = "kobkrit@iapp.co.th"
5
+ __version__ = "2.0.0"
6
+
7
+ from iapp_ai.module_api import api
8
+
9
+ __all__ = ["api"]
@@ -0,0 +1,55 @@
1
+ """Copies of three iapp-core helpers that iapp-core 0.1.1, the newest release on PyPI, lacks.
2
+
3
+ The iapp-core in this repo has ``build_output_path``, ``build_url`` and ``open_input_files``,
4
+ but it lacks the timeout settings that only the published 0.1.1 has, so it cannot be released
5
+ as it is. Until one iapp-core release has both, iapp_ai uses these copies, which need only what
6
+ every iapp-core release on PyPI has. Once iapp-ai requires an iapp-core with these helpers,
7
+ import them from iapp_core again and delete this module.
8
+ """
9
+
10
+ import os
11
+ from contextlib import contextmanager
12
+ from typing import Any, Dict, Iterator, List, Optional
13
+ from urllib.parse import urlencode
14
+
15
+ from iapp_core import resolve_input_file, resolve_output_path
16
+
17
+
18
+ def build_url(base: str, path: str = "", params: Optional[Dict[str, Any]] = None) -> str:
19
+ """Join ``base`` and ``path`` and append a URL-encoded query string, as ``iapp_core.build_url``.
20
+
21
+ ``params`` values are percent-encoded, so Thai text is safe, and ``None`` values are dropped.
22
+ """
23
+ url = base.rstrip("/")
24
+ if path:
25
+ url = f"{url}/{path.lstrip('/')}"
26
+ if params:
27
+ clean = {k: v for k, v in params.items() if v is not None}
28
+ if clean:
29
+ url = f"{url}?{urlencode(clean, doseq=True)}"
30
+ return url
31
+
32
+
33
+ @contextmanager
34
+ def open_input_files(file_paths: List[str], mode: str = "rb") -> Iterator[List]:
35
+ """Open several input files and close every handle on exit, as ``iapp_core.open_input_files``."""
36
+ handles: List = []
37
+ try:
38
+ for file_path in file_paths:
39
+ handles.append(open(resolve_input_file(file_path), mode))
40
+ yield handles
41
+ finally:
42
+ for handle in handles:
43
+ handle.close()
44
+
45
+
46
+ def default_output_dir() -> str:
47
+ """``IAPP_OUTPUT_DIR``, or ``media`` when it is not set, as ``iapp_core.default_output_dir``."""
48
+ return os.environ.get("IAPP_OUTPUT_DIR", "").strip() or "media"
49
+
50
+
51
+ def build_output_path(filename: str, output_path: Optional[str] = None) -> str:
52
+ """Where to save a generated file, with its directory created, as ``iapp_core.build_output_path``:
53
+ ``output_path`` when given, else ``default_output_dir()/filename``."""
54
+ target = output_path if output_path else os.path.join(default_output_dir(), filename)
55
+ return resolve_output_path(target)