You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
2 years ago
|
from aiohttp import web
|
||
|
import utils.web
|
||
|
import utils.text
|
||
|
from extend.hangul_romanize import Transliter
|
||
|
from extend.hangul_romanize.rule import academic
|
||
|
|
||
|
class Hanja:
|
||
|
@staticmethod
|
||
|
def convertToRomaja(self, hanja: str):
|
||
|
transliter = Transliter(academic)
|
||
|
segList = utils.text.splitAscii(hanja)
|
||
|
sentenceList = []
|
||
|
for seg in segList:
|
||
|
if seg == " ":
|
||
|
sentenceList.append("-")
|
||
|
elif utils.text.isAscii(seg):
|
||
|
if utils.text.isAsciiPunc(seg):
|
||
|
sentenceList.append(seg)
|
||
|
else:
|
||
|
sentenceList.append([seg])
|
||
|
else:
|
||
|
roma = transliter.translit(seg)
|
||
|
sentenceList.append(roma.split(" "))
|
||
|
return sentenceList
|
||
|
|
||
|
@staticmethod
|
||
|
async def hanja2roma(request: web.Request):
|
||
|
params = await utils.web.get_param(request, {
|
||
|
"sentence": {
|
||
|
"required": True,
|
||
|
},
|
||
|
})
|
||
|
sentence = params.get('sentence')
|
||
|
|
||
|
data = Hanja.convertToRomaja(sentence)
|
||
|
return await utils.web.api_response(1, data, request=request)
|