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 render_template
|
||||
import json
|
||||
import os
|
||||
#import os
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
def get_dictionary(filename='fastionary/enfr.json'):
|
||||
print (filename)
|
||||
if os.path.exists(filename):
|
||||
with open (filename, 'r') as json_file:
|
||||
dictionary = json.load(json_file)
|
||||
else:
|
||||
dictionary = {}
|
||||
# what happens if dictionary not found?
|
||||
# return dummy dictionary?
|
||||
# display that no dictionary file was found
|
||||
# where should this be handled
|
||||
return dictionary
|
||||
#def get_dictionary(filename='fastionary/enfr.json'):
|
||||
# print (filename)
|
||||
# if os.path.exists(filename):
|
||||
# with open (filename, 'r') as json_file:
|
||||
# dictionary = json.load(json_file)
|
||||
# else:
|
||||
# dictionary = {}
|
||||
# # what happens if dictionary not found?
|
||||
# # return dummy dictionary?
|
||||
# # display that no dictionary file was found
|
||||
# # where should this be handled
|
||||
# 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()
|
||||
translation = None
|
||||
if word != None or word != '':
|
||||
translation = dictionary.get(word)
|
||||
return translation
|
||||
|
||||
def get_translations(word, file_path='fastionary/data/detw.jsonl'):
|
||||
with open(file_path, 'r', encoding='utf-8') as file:
|
||||
for line in file:
|
||||
entry = json.loads(line)
|
||||
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('/')
|
||||
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