import spacy import neuralcoref import re nlp = spacy.load('en') neuralcoref.add_to_pipe(nlp, conv_dict={'Jack Porter': ['man', 'CEO'], 'Cognizer':['company', 'organization']}) history = "" while True: text = input("Enter your text.\n") if text != "exit": if not text.endswith('?') or text.endswith('.'): text = text + '.' # if text.endswith('?'): # text = text.strip('?') + '.' history = history + text + ' ' doc = nlp(history) resolved_utter = doc._.coref_resolved.split('. ')[-1] print(f"History: {history}") print(f"Query: {resolved_utter}") else: break