Commit
·
4ae59b6
1
Parent(s):
fdea6f1
Update code
Browse files- routers/soundex.py +5 -1
- routers/util.py +21 -4
routers/soundex.py
CHANGED
@@ -6,6 +6,10 @@ from pythainlp.soundex import (
|
|
6 |
soundex as py_soundex
|
7 |
)
|
8 |
from enum import Enum
|
|
|
|
|
|
|
|
|
9 |
|
10 |
router = APIRouter()
|
11 |
|
@@ -17,7 +21,7 @@ class SoundexEngine(str, Enum):
|
|
17 |
prayut_and_somchaip = "prayut_and_somchaip"
|
18 |
|
19 |
|
20 |
-
@router.post('/soundex')
|
21 |
def soundex(word: str, engine: SoundexEngine = "udom83"):
|
22 |
"""
|
23 |
This api converts Thai text into phonetic code.
|
|
|
6 |
soundex as py_soundex
|
7 |
)
|
8 |
from enum import Enum
|
9 |
+
from pydantic import BaseModel
|
10 |
+
|
11 |
+
class SoundexResponse(BaseModel):
|
12 |
+
soundex: str = ""
|
13 |
|
14 |
router = APIRouter()
|
15 |
|
|
|
21 |
prayut_and_somchaip = "prayut_and_somchaip"
|
22 |
|
23 |
|
24 |
+
@router.post('/soundex', response_model=SoundexResponse)
|
25 |
def soundex(word: str, engine: SoundexEngine = "udom83"):
|
26 |
"""
|
27 |
This api converts Thai text into phonetic code.
|
routers/util.py
CHANGED
@@ -8,9 +8,26 @@ from pythainlp.util import (
|
|
8 |
tone_detector as py_tone_detector,
|
9 |
thaiword_to_num as py_thaiword_to_num
|
10 |
)
|
|
|
11 |
router = APIRouter()
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
def bahttext(number: float):
|
15 |
"""
|
16 |
This api converts a number to Thai text and adds a suffix “บาท” (Baht).
|
@@ -21,7 +38,7 @@ def bahttext(number: float):
|
|
21 |
)
|
22 |
|
23 |
|
24 |
-
@router.post('/normalize')
|
25 |
def normalize(text: str):
|
26 |
"""
|
27 |
Normalize and clean Thai text
|
@@ -32,7 +49,7 @@ def normalize(text: str):
|
|
32 |
)
|
33 |
|
34 |
|
35 |
-
@router.post('/tone_detector')
|
36 |
def tone_detector(syllable: str):
|
37 |
"""
|
38 |
Thai tone detector for word.
|
@@ -43,7 +60,7 @@ def tone_detector(syllable: str):
|
|
43 |
)
|
44 |
|
45 |
|
46 |
-
@router.post("/thaiword_to_num")
|
47 |
def thaiword_to_num(text: str):
|
48 |
"""
|
49 |
Converts the spelled-out numerals in Thai scripts into an actual integer.
|
|
|
8 |
tone_detector as py_tone_detector,
|
9 |
thaiword_to_num as py_thaiword_to_num
|
10 |
)
|
11 |
+
from pydantic import BaseModel
|
12 |
router = APIRouter()
|
13 |
|
14 |
+
|
15 |
+
class BahttextResponse(BaseModel):
|
16 |
+
bahttext: str
|
17 |
+
|
18 |
+
|
19 |
+
class NormalizeResponse(BaseModel):
|
20 |
+
text: str
|
21 |
+
|
22 |
+
|
23 |
+
class ToneResponse(BaseModel):
|
24 |
+
tone: str
|
25 |
+
|
26 |
+
class NumeralsResponse(BaseModel):
|
27 |
+
number: int
|
28 |
+
|
29 |
+
|
30 |
+
@router.post('/bahttext', response_model=BahttextResponse)
|
31 |
def bahttext(number: float):
|
32 |
"""
|
33 |
This api converts a number to Thai text and adds a suffix “บาท” (Baht).
|
|
|
38 |
)
|
39 |
|
40 |
|
41 |
+
@router.post('/normalize', response_model=NormalizeResponse)
|
42 |
def normalize(text: str):
|
43 |
"""
|
44 |
Normalize and clean Thai text
|
|
|
49 |
)
|
50 |
|
51 |
|
52 |
+
@router.post('/tone_detector', response_model=ToneResponse)
|
53 |
def tone_detector(syllable: str):
|
54 |
"""
|
55 |
Thai tone detector for word.
|
|
|
60 |
)
|
61 |
|
62 |
|
63 |
+
@router.post("/thaiword_to_num", response_model=NumeralsResponse)
|
64 |
def thaiword_to_num(text: str):
|
65 |
"""
|
66 |
Converts the spelled-out numerals in Thai scripts into an actual integer.
|