choix-spe/main5.py

46 lines
1.1 KiB
Python
Raw Permalink Normal View History

2023-10-12 20:03:37 +00:00
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])