wannaphong commited on
Commit
59fb62a
·
1 Parent(s): 8fe7306

Add spell and util

Browse files
Files changed (5) hide show
  1. app.py +4 -2
  2. requirements.txt +5 -5
  3. routers/soundex.py +1 -1
  4. routers/spell.py +32 -0
  5. routers/util.py +20 -0
app.py CHANGED
@@ -1,7 +1,7 @@
1
  from fastapi import Depends, FastAPI, Header, HTTPException
2
  from fastapi.middleware.cors import CORSMiddleware
3
  from fastapi.responses import RedirectResponse
4
- from routers import tokenize, soundex
5
  import pythainlp
6
 
7
 
@@ -50,4 +50,6 @@ def version():
50
  return {"version": pythainlp.__version__}
51
 
52
  app.include_router(tokenize.router, prefix="/tokenize", tags=["Tokenize"])
53
- app.include_router(soundex.router, prefix="/soundex", tags=["Soundex"])
 
 
 
1
  from fastapi import Depends, FastAPI, Header, HTTPException
2
  from fastapi.middleware.cors import CORSMiddleware
3
  from fastapi.responses import RedirectResponse
4
+ from routers import tokenize, soundex, util, spell
5
  import pythainlp
6
 
7
 
 
50
  return {"version": pythainlp.__version__}
51
 
52
  app.include_router(tokenize.router, prefix="/tokenize", tags=["Tokenize"])
53
+ app.include_router(soundex.router, prefix="/soundex", tags=["Soundex"])
54
+ app.include_router(spell.router, prefix="/spell", tags=["Spell"])
55
+ app.include_router(util.router, prefix="/util", tags=["Util"])
requirements.txt CHANGED
@@ -1,6 +1,6 @@
1
- fastapi
2
- uvicorn[standard]
3
  pythainlp==5.0.5
4
- python-crfsuite
5
- ssg
6
- tltk
 
1
+ fastapi==0.115.6
2
+ uvicorn[standard]==0.34.0
3
  pythainlp==5.0.5
4
+ python-crfsuite==0.9.11
5
+ ssg==0.0.8
6
+ tltk==1.9.1
routers/soundex.py CHANGED
@@ -18,6 +18,6 @@ class SoundexEngine(str, Enum):
18
  @router.post('/soundex')
19
  def soundex(text: str, engine: SoundexEngine = "udom83"):
20
  """
21
- Word tokenize
22
  """
23
  return {"soundex": py_soundex(text=text, engine=engine)}
 
18
  @router.post('/soundex')
19
  def soundex(text: str, engine: SoundexEngine = "udom83"):
20
  """
21
+ This api converts Thai text into phonetic code.
22
  """
23
  return {"soundex": py_soundex(text=text, engine=engine)}
routers/spell.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ from fastapi import APIRouter
3
+ from pythainlp.spell import (
4
+ correct as py_correct,
5
+ spell as py_spell
6
+ )
7
+ from enum import Enum
8
+ from typing import List, Optional
9
+ from pydantic import BaseModel
10
+
11
+ class CorrectEngine(str, Enum):
12
+ pn = "pn"
13
+
14
+ class CorrectResponse(BaseModel):
15
+ word: str = ""
16
+
17
+ class SpellEngine(str, Enum):
18
+ pn = "pn"
19
+
20
+ class SpellResponse(BaseModel):
21
+ word: str = ""
22
+
23
+ router = APIRouter()
24
+
25
+
26
+ @router.post('/correct', response_model=CorrectResponse)
27
+ def correct(word: float, engine: CorrectEngine = "pn"):
28
+ return {"word": py_correct(word, engine=engine)}
29
+
30
+ @router.post('/spell', response_model=SpellResponse)
31
+ def spell(word: float, engine: SpellEngine = "pn"):
32
+ return {"word": py_spell(word, engine=engine)}
routers/util.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ from fastapi import APIRouter
3
+ from pythainlp.util import (
4
+ bahttext as py_bahttext,
5
+ normalize as py_normalize,
6
+ tone_detector as py_tone_detector
7
+ )
8
+ router = APIRouter()
9
+
10
+ @router.post('/bahttext')
11
+ def bahttext(number: float):
12
+ return {"bahttext": py_bahttext(number)}
13
+
14
+ @router.post('/normalize')
15
+ def normalize(text: str):
16
+ return {"text": py_normalize(text)}
17
+
18
+ @router.post('/tone_detector')
19
+ def tone_detector(syllable: str):
20
+ return {"tone": py_tone_detector(syllable)}