Check if romanizations already exist in database; transliterate the whole sentence instead of just one word
This commit is contained in:
@@ -20,7 +20,7 @@ function updateTranslations(response) {
|
||||
const romanizations = data;
|
||||
document.querySelectorAll(".romanizationText").forEach(element => {
|
||||
if (element.id.replace("Romanization", "") in romanizations) {
|
||||
element.textContent = "(" + romanizations[element.id.replace("Romanization", "")][0] + ")";
|
||||
element.textContent = "(" + romanizations[element.id.replace("Romanization", "")] + ")";
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@@ -21,6 +21,7 @@ from uuid import uuid4
|
||||
from datetime import datetime
|
||||
import traceback
|
||||
import enum
|
||||
import sqlite3
|
||||
|
||||
from .utils import LANG_CODE_TO_DISPLAY_NAME, RTL_LANG_CODES, LANG_CODE_TO_SCRIPT_CODE
|
||||
|
||||
@@ -127,7 +128,7 @@ def reverse_xlit_api(lang_code, word):
|
||||
|
||||
try:
|
||||
## Limit char count to --> 70
|
||||
xlit_result = ENGINE["indic2en"].translit_word(word[:70], lang_code, topk=num_suggestions)
|
||||
xlit_result = ENGINE["indic2en"].translit_sentence(word, lang_code)
|
||||
except Exception as e:
|
||||
xlit_result = XlitError.internal_err
|
||||
|
||||
@@ -203,7 +204,7 @@ def romanizeHandler():
|
||||
"kn": "kn",
|
||||
"mai": "mai",
|
||||
"ml": "ml",
|
||||
"mni_mtei": "mni",
|
||||
"mni-Mtei": "mni",
|
||||
"mr": "mr",
|
||||
"ne": "ne",
|
||||
"or": "or",
|
||||
@@ -216,6 +217,26 @@ def romanizeHandler():
|
||||
rtv = dict()
|
||||
|
||||
data = request.get_json(force=True)
|
||||
|
||||
# Check if database contains the romanizations already
|
||||
englishWord = data['en']
|
||||
print(englishWord)
|
||||
con = sqlite3.connect("../translations.db")
|
||||
cur = con.cursor()
|
||||
cur.execute("CREATE TABLE IF NOT EXISTS romanizations AS SELECT * FROM translations WHERE 0") # Copy schema from 'translations' table
|
||||
cur.execute('SELECT * FROM romanizations WHERE english = ?', (englishWord,))
|
||||
romanizations = cur.fetchall()
|
||||
columnNames = [column[0] for column in cur.description]
|
||||
romanizationsDict = []
|
||||
if len(romanizations) > 0:
|
||||
for row in romanizations:
|
||||
row_dict = {columnNames[i]: row[i] for i in range(len(columns))}
|
||||
romanizationsDict.append(row_dict)
|
||||
json_data = json.dumps(romanizationsdata, indent=4)
|
||||
print(json_data)
|
||||
# if len(romanizations) != 0:
|
||||
|
||||
# Assuming the romanizations didn't exist before
|
||||
for key in data:
|
||||
if key in langCodeLookup:
|
||||
langCode = langCodeLookup[key]
|
||||
@@ -223,4 +244,8 @@ def romanizeHandler():
|
||||
response = reverse_xlit_api(langCode, text)
|
||||
responseJson = response.get_json()
|
||||
rtv[key] = responseJson['result']
|
||||
return jsonify(rtv)
|
||||
|
||||
rtvJson = jsonify(rtv)
|
||||
|
||||
con.close()
|
||||
return rtvJson
|
||||
|
Reference in New Issue
Block a user