mirror of
https://github.com/magnum-opus-tender-hack/backend.git
synced 2024-11-25 18:53:43 +03:00
Merge pull request #5 from magnum-opus-tender-hack/speller-translate
add speller and translate
This commit is contained in:
commit
497b930ca1
6
app/search/services/spell_check.py
Normal file
6
app/search/services/spell_check.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
import requests as r
|
||||
|
||||
|
||||
def spell_check(word: str) -> str:
|
||||
res = r.get(f'https://speller.yandex.net/services/spellservice.json/checkText?text={word}')
|
||||
return res.json()[0]['s'][0]
|
13
app/search/services/translate.py
Normal file
13
app/search/services/translate.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
import requests as r
|
||||
from conf.settings.base import YANDEX_DICT_API_KEY
|
||||
from itertools import chain
|
||||
from typing import List
|
||||
|
||||
|
||||
def translate_ru_en(word: str) -> List[str]:
|
||||
res = r.get(f"https://dictionary.yandex.net/api/v1/dicservice.json/lookup?key={YANDEX_DICT_API_KEY}&lang=ru-en&text={word}")
|
||||
return [i['text'] for i in chain(*[j['tr']for j in res.json()['def']])]
|
||||
|
||||
def translate_en_ru(word: str) -> List[str]:
|
||||
res = r.get(f"https://dictionary.yandex.net/api/v1/dicservice.json/lookup?key={YANDEX_DICT_API_KEY}&lang=en-ru&text={word}")
|
||||
return [i['text'] for i in chain(*[j['tr']for j in res.json()['def']])]
|
Loading…
Reference in New Issue
Block a user