You've already forked ui-cviko1
2.3 KiB
2.3 KiB
In [4]:
import random
import re
no_responses = [
"I can't answer that.",
"I don't know, sorry.",
"I can't understand you.",
"Can you elaborate, please?"
]
responses = {
"name": [
"my name is AI-BOT",
"they call me AI-BOT",
"I go by AI-BOT"
],
"weather": [
"the weather is sunny",
"it's sunny today"
],
"hockey": [
"good winter time!",
"we have to wait for the lake to be frozen"
]
}
communication_stack = []
intent_database = [key for key in responses.keys()]
while True:
message = input("> ")
if message == "bye":
print("< Bye")
break
message = re.sub("[ ,.?!:;]", " ", message)
words = message.split()
for word in words:
if word in intent_database:
communication_stack.append(word)
if communication_stack:
print("<", random.choice(responses[communication_stack.pop()]))
else:
print("<", random.choice(no_responses))
In [ ]: