Skip to content

Instantly share code, notes, and snippets.

@Deepayan137
Created December 24, 2021 07:55
Show Gist options
  • Save Deepayan137/598cd31761165037bc20c38a70b70e49 to your computer and use it in GitHub Desktop.
Save Deepayan137/598cd31761165037bc20c38a70b70e49 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment