File size: 911 Bytes
8fe7306
9dbb134
 
0c9becc
8fe7306
 
 
 
4ae59b6
 
 
 
8fe7306
 
 
 
 
 
 
 
 
 
 
4ae59b6
1bc58c6
8fe7306
59fb62a
b9def7b
 
 
1bc58c6
fdea6f1
8fe7306
0c9becc
fdea6f1
737b250
9dbb134
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
import json
from fastapi import APIRouter, Response
from fastapi.responses import JSONResponse
from pythainlp.soundex import (
    soundex as py_soundex
)
from enum import Enum
from pydantic import BaseModel

class SoundexResponse(BaseModel):
    soundex: str = ""

router = APIRouter()


class SoundexEngine(str, Enum):
    udom83 = "udom83"
    lk82 = "lk82"
    metasound = "metasound"
    prayut_and_somchaip = "prayut_and_somchaip"


@router.post('/soundex', response_model=SoundexResponse)
def soundex(word: str, engine: SoundexEngine = "udom83"):
    """
    This api converts Thai text into phonetic code.

    ## Input

    - **word**:  A word that want into phonetic code.
    - **engine**: Soundex Engine (default is udom83
    """
    return JSONResponse(
        {"soundex": py_soundex(text=word, engine=engine)},
        media_type="application/json; charset=utf-8",
    )