Merge pull request #6 from magnum-opus-tender-hack/speller-translate

change translate
This commit is contained in:
Alexandr Karpov 2022-10-22 18:26:38 +03:00 committed by GitHub
commit 784d6699de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 6 deletions

View File

@ -1,3 +1,4 @@
DJANGO_DEBUG=yes
DATABASE_URL=postgres://postgres:debug@127.0.0.1:5432/tenderhack
CELERY_BROKER_URL=redis://localhost:6379/0
YANDEX_DICT=<your_yandex_dict_api_key>

View File

@ -1,4 +1,5 @@
from pathlib import Path
import os
import environ
@ -38,6 +39,8 @@ LOCALE_PATHS = [str(APPS_DIR / "locale")]
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {"default": env.db("DATABASE_URL")}
DATABASES["default"]["ATOMIC_REQUESTS"] = True
YANDEX_DICT_API_KEY = env.str('YANDEX_DICT')
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

View File

@ -1,10 +1,18 @@
import requests as r
from spellchecker import SpellChecker
speller_ru = SpellChecker(language='ru')
speller_eng = SpellChecker(language='en')
def spell_check(word: str) -> str:
res = r.get(
f"https://speller.yandex.net/services/spellservice.json/checkText?text={word}"
)
if not res.json():
def spell_check_ru(word: str) -> str:
res = speller_ru.correction(word)
if not len(res):
return word
return res.json()[0]["s"][0]
return res
def spell_check_en(word: str) -> str:
res = speller_eng.correction(word)
if not len(res):
return word
return res

View File

@ -10,3 +10,5 @@ redis==4.3.4
psycopg2-binary==2.9.4
celery==5.2.7
pyspellchecker==0.7.0