use wiktionary data
This commit is contained in:
parent
4690b7f715
commit
6ab5c19de8
@ -2,29 +2,42 @@ from flask import Flask
|
|||||||
from flask import request
|
from flask import request
|
||||||
from flask import render_template
|
from flask import render_template
|
||||||
import json
|
import json
|
||||||
import os
|
#import os
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
def get_dictionary(filename='fastionary/enfr.json'):
|
#def get_dictionary(filename='fastionary/enfr.json'):
|
||||||
print (filename)
|
# print (filename)
|
||||||
if os.path.exists(filename):
|
# if os.path.exists(filename):
|
||||||
with open (filename, 'r') as json_file:
|
# with open (filename, 'r') as json_file:
|
||||||
dictionary = json.load(json_file)
|
# dictionary = json.load(json_file)
|
||||||
else:
|
# else:
|
||||||
dictionary = {}
|
# dictionary = {}
|
||||||
# what happens if dictionary not found?
|
# # what happens if dictionary not found?
|
||||||
# return dummy dictionary?
|
# # return dummy dictionary?
|
||||||
# display that no dictionary file was found
|
# # display that no dictionary file was found
|
||||||
# where should this be handled
|
# # where should this be handled
|
||||||
return dictionary
|
# return dictionary
|
||||||
|
#
|
||||||
|
#def get_translations(word):
|
||||||
|
# dictionary=get_dictionary()
|
||||||
|
# translation = None
|
||||||
|
# if word != None or word != '':
|
||||||
|
# translation = dictionary.get(word)
|
||||||
|
# return translation
|
||||||
|
|
||||||
def get_translations(word):
|
|
||||||
dictionary=get_dictionary()
|
def get_translations(word, file_path='fastionary/data/detw.jsonl'):
|
||||||
translation = None
|
with open(file_path, 'r', encoding='utf-8') as file:
|
||||||
if word != None or word != '':
|
for line in file:
|
||||||
translation = dictionary.get(word)
|
entry = json.loads(line)
|
||||||
return translation
|
if entry.get('word') == word:
|
||||||
|
if 'translations' in entry and entry['translations']:
|
||||||
|
for sense in entry['translations']:
|
||||||
|
if sense['lang_code'] == 'tw':
|
||||||
|
return sense['word']
|
||||||
|
# return entry['translations'][0]['word']
|
||||||
|
return None
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def trans(q=None):
|
def trans(q=None):
|
||||||
|
|||||||
28
fastionary/data/detw.jsonl
Normal file
28
fastionary/data/detw.jsonl
Normal file
File diff suppressed because one or more lines are too long
1
fastionary/data/sub-detw.json
Normal file
1
fastionary/data/sub-detw.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"word": "April", "pos": "noun", "lang_code": "de", "translations": [{"sense": "der vierte Monat des Gregorianischen Kalenders", "word": "Oforisuo", "lang_code": "tw", "lang": "Twi", "sense_index": "1"}], "tags": ["masculine"]}
|
||||||
1
fastionary/data/sub-twde.json
Normal file
1
fastionary/data/sub-twde.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"word": "kunu", "pos": "noun", "tw", "lang": "Twi", "translations": [{"sense": "verheirateter Mann; Mann, mit dem eine Frau verheiratet ist: Ehemann, Ehegatte, Gatte, Mann", "word": "Ehemann", "lang_code": "de", "lang": "Deutsch", "sense_index": "1", "tags": ["masculine"]}, {"sense": "verheirateter Mann; Mann, mit dem eine Frau verheiratet ist: Ehemann, Ehegatte, Gatte, Mann", "word": "Ehegatte", "lang_code": "de", "lang": "Deutsch", "sense_index": "1", "tags": ["masculine"]}, {"sense": "verheirateter Mann; Mann, mit dem eine Frau verheiratet ist: Ehemann, Ehegatte, Gatte, Mann", "word": "Gatte", "lang_code": "de", "lang": "Deutsch", "sense_index": "1", "tags": ["masculine"]}, {"sense": "verheirateter Mann; Mann, mit dem eine Frau verheiratet ist: Ehemann, Ehegatte, Gatte, Mann", "word": "Mann", "lang_code": "de", "lang": "Deutsch", "sense_index": "1", "tags": ["masculine"]}]}
|
||||||
Loading…
Reference in New Issue
Block a user