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)