Commit
·
97cd79a
1
Parent(s):
737b250
Add thaiword_to_num
Browse files- routers/util.py +19 -1
routers/util.py
CHANGED
@@ -4,7 +4,8 @@ from fastapi import APIRouter, Response
|
|
4 |
from pythainlp.util import (
|
5 |
bahttext as py_bahttext,
|
6 |
normalize as py_normalize,
|
7 |
-
tone_detector as py_tone_detector
|
|
|
8 |
)
|
9 |
router = APIRouter()
|
10 |
|
@@ -39,3 +40,20 @@ def tone_detector(syllable: str):
|
|
39 |
json.dumps({"tone": py_tone_detector(syllable)}, ensure_ascii=False),
|
40 |
media_type="application/json; charset=utf-8",
|
41 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
from pythainlp.util import (
|
5 |
bahttext as py_bahttext,
|
6 |
normalize as py_normalize,
|
7 |
+
tone_detector as py_tone_detector,
|
8 |
+
thaiword_to_num as py_thaiword_to_num
|
9 |
)
|
10 |
router = APIRouter()
|
11 |
|
|
|
40 |
json.dumps({"tone": py_tone_detector(syllable)}, ensure_ascii=False),
|
41 |
media_type="application/json; charset=utf-8",
|
42 |
)
|
43 |
+
|
44 |
+
|
45 |
+
@router.post("/thaiword_to_num")
|
46 |
+
def thaiword_to_num(text: str):
|
47 |
+
"""
|
48 |
+
Converts the spelled-out numerals in Thai scripts into an actual integer.
|
49 |
+
|
50 |
+
Example: 'สองล้านสามแสนหกร้อยสิบสอง' => 2300612, 'ศูนย์' => 0
|
51 |
+
|
52 |
+
## Input
|
53 |
+
|
54 |
+
- **text**: Spelled-out numerals in Thai scripts
|
55 |
+
"""
|
56 |
+
return Response(
|
57 |
+
json.dumps({"number": py_thaiword_to_num(text)}, ensure_ascii=False),
|
58 |
+
media_type="application/json; charset=utf-8",
|
59 |
+
)
|