From 9033dca7e31f73115eef39772b7f18bf2a55feb7 Mon Sep 17 00:00:00 2001 From: raphael Date: Thu, 12 Oct 2023 22:03:37 +0200 Subject: [PATCH] main upload --- main5.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 main5.py diff --git a/main5.py b/main5.py new file mode 100644 index 0000000..a5019b3 --- /dev/null +++ b/main5.py @@ -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])