Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Commit

Permalink
Switched to Apertium for translation
Browse files Browse the repository at this point in the history
  • Loading branch information
rtrevinnoc committed Feb 21, 2021
1 parent f2106a5 commit 7594ec1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Monad.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ def inferLanguage(string: str) -> str:
try:
return Detector(string).language.code
except:
return "autodetect"
return "unk"

def mintTokens(queryVec: np.array, answerVec: np.array) -> int:
if WEB3API.isConnected():
Expand Down
3 changes: 2 additions & 1 deletion bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ pip3 install -U numexpr
pip3 install -U flask-caching
pip3 install -U pillow
pip3 install -U web3
pip3 install -U translate
pip3 install -U languagecodes
pip3 install -U banal

python3 -m spacy download en_core_web_sm
python3 -c "import nltk; nltk.download('punkt')"
Expand Down
14 changes: 10 additions & 4 deletions future.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#########################################################################

from Monad import *
import os.path, os, shutil, json, random, sys, socket, re, mimetypes, datetime, lmdb, hnswlib, time, bson, requests, socket, ast, functools, asyncio, concurrent.futures, itertools, mimetypes, io, threading
import os.path, os, shutil, json, random, sys, socket, re, mimetypes, datetime, lmdb, hnswlib, time, bson, requests, socket, ast, functools, asyncio, concurrent.futures, itertools, mimetypes, io, threading, languagecodes
import numpy as np
import numexpr as ne
from flask import (Flask, render_template, request, redirect,
Expand All @@ -38,7 +38,6 @@
from bs4 import BeautifulSoup
from config import HOST_NAME, PEER_PORT, CONTACT, MAINTAINER, FIRST_NOTICE, SECOND_NOTICE, DONATE, COLABORATE, CACHE_TIMEOUT, CACHE_THRESHOLD
from PIL import Image
from translate import Translator

bson.loads = bson.BSON.decode
bson.dumps = bson.BSON.encode
Expand Down Expand Up @@ -406,8 +405,15 @@ def answer(query: str, page: int) -> jsonify:
query = queryBeforePreprocessing
query = query.lower().strip()
if queryLanguage != "en":
translator = Translator(from_lang=queryLanguage, to_lang="en")
query = translator.translate(query)
try:
query = requests.get("https://www.apertium.org/apy/translate", params={'q': query, 'markUnknown': 'no', 'langpair': languagecodes.iso_639_alpha3(queryLanguage) + '|eng'}).json()['responseData']['translatedText']
except:
return {
"answer": "Could not translate input.",
"small_summary": "Could not translate input.",
"corrected": query,
"urls": []
}
try:
q_vec = getSentenceMeanVector(query)
except:
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ uWSGI==2.0.19.1
Werkzeug==0.16.1
wordnet==0.0.1b2
WTForms==2.3.3
translate=3.5.0

0 comments on commit 7594ec1

Please sign in to comment.