use wiktionary data

This commit is contained in:
oni@bor 2026-01-15 00:17:39 +01:00
parent 4690b7f715
commit 6ab5c19de8
4 changed files with 62 additions and 19 deletions

View File

@ -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):

File diff suppressed because one or more lines are too long

View 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"]}

View 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"]}]}