main upload

This commit is contained in:
raphael 2023-10-12 22:03:37 +02:00
parent b80db70761
commit 9033dca7e3

45
main5.py Normal file
View file

@ -0,0 +1,45 @@
import jaro
import json
# Load database
print("Loading database ...")
with open("data.json", "r") as file:
database = json.loads(file.read())
prompt = input("name > ")
tokens = prompt.split()
# Finding possible words index
possible_words = []
for t in tokens:
found_words = []
for w in database["lexique"]["index"].keys():
if jaro.jaro_winkler_metric(w, t) > 0.93:
index = database["lexique"]["index"][w]
if index not in found_words:
found_words.append(index)
if found_words:
possible_words.append(found_words)
print(possible_words)
# Test every formation
to_test = []
test_passed = []
for f in database["formations"].keys():
checked_count = 0
for ti in database["formations"][f]["recW"].keys():
for found_index in possible_words:
if int(ti) in found_index:
checked_count += 1
break
if checked_count == len(possible_words):
test_passed.append(f)
# Print the result
for f in test_passed:
print(database["formations"][f]["nm"], "at :", list(database["formations"][f]["recS"].keys())[1])