From d2a76adde6625afff16efa62a7b08e3da39c4070 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Fri, 11 Oct 2024 16:06:44 +0200 Subject: [PATCH] Import readline --- cemantix.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cemantix.py b/cemantix.py index 37e5037..697f005 100644 --- a/cemantix.py +++ b/cemantix.py @@ -1,18 +1,20 @@ from gensim.models import KeyedVectors from colorama import Fore, Back, Style import argparse +import readline import random +import time def cemantix(model, word=None): if word is None: rd = random.randint(0, len(model)) word = model.index_to_key[rd] - while "_" in word: + while '_' in word or '-' in word: rd += 1 word = model.index_to_key[rd] - nearest = [i[0] for i in model.most_similar(word, topn=1000)] + nearest = [word]+[i[0] for i in model.most_similar(word, topn=999)] def get_rank(guess): if guess not in nearest: return None @@ -40,6 +42,7 @@ def cemantix(model, word=None): while True: try: guess = input(Style.BRIGHT+"Your guess > "+Style.RESET_ALL).strip() + readline.add_history(guess) except (EOFError, KeyboardInterrupt): print("The word was "+Style.BRIGHT+word+Style.RESET_ALL) print("Goodbye!") @@ -56,6 +59,7 @@ def cemantix(model, word=None): print(chr(27) + "[2J") print(formatted_status(guesses, last=guess)) if guess == word: + time.sleep(1) print(Fore.GREEN+"Correct!"+Style.RESET_ALL+f" {len(guesses)} tries.") return len(guesses)