Building Chatbots in Python
Alan Nichol
Co-founder and CTO, Rasa
def respond(message, params):
# update params with entities in message
# run query
# pick response
return response, params
# initialise params
params = {}
# message comes in
response, params = respond(message, params)
"where should I go for dinner?"
"no I don't like sushi"
"what about Sally's Sushi Place?"
"ok, what about Joe's Steakhouse?"
doc = nlp('not sushi, maybe pizza?')
indices = [1, 4]
ents, negated_ents = [], []
start = 0 for i in indices: phrase = "{}".format(doc[start:i]) if "not" in phrase or "n't" in phrase: negated_ents.append(doc[i]) else: ents.append(doc[i]) start = i
Building Chatbots in Python