from nltk.chat.util import Chat, reflections#Pairs is a list of patterns and responses.
pairs = [
[
r"(.*)my name is (.*)",
["Hello %2, How are you today ?",]
],
[
r"(.*)help(.*) ",
["I can help you ",]
],
[
r"(.*) your name ?",
["My name is Denver, but you can just call me robot and I'm a chatbot .",]
],
[
r"how are you (.*) ?",
["I'm doing very well", "i am great !"]
],
[
r"sorry (.*)",
["Its alright","Its OK, never mind that",]
],
[
r"i'm (.*) (good|well|okay|ok)",
["Nice to hear that","Alright, great !",]
],
[
r"(hi|hey|hello|hola|holla)(.*)",
["Hello", "Hey there",]
],
[
r"what (.*) want ?",
["Make me an offer I can't refuse",]
],
[
r"(.*)created(.*)",
["Aman Kharwal created me using Python's NLTK library ","top secret ;)",]
],
[
r"(.*) (location|city) ?",
['New Delhi, India',]
],
[
r"(.*)raining in (.*)",
["No rain in the past 4 days here in %2","In %2 there is a 50% chance of rain",]
],
[
r"how (.*) health (.*)",
["Health is very important, but I am a computer, so I don't need to worry about my health ",]
],
[
r"(.*)(sports|game|sport)(.*)",
["I'm a very big fan of basketball",]
],
[
r"who (.*) (Cricketer|Batsman)?",
["Virat Kohli"]
],
[
r"quit",
["Bye for now. See you soon :) ","It was nice talking to you. See you soon :)"]
],
[
r"(.*)",
['That is nice to hear']
],
]#default message at the start of chat
print("Hi, I'm Denver and I like to chat\nPlease type lowercase English language to start a conversation. Type quit to leave ")
#Create Chat Bot
chat = Chat(pairs, reflections)
#Start conversation
chat.converse()Hi, I'm Denver and I like to chat
Please type lowercase English language to start a conversation. Type quit to leave
>Hi Denver, My name is Niquan
Hello niquan , How are you today ?
>Im good how are you?
That is nice to hear
>hows your health?
That is nice to hear
>how is your health?
That is nice to hear
>ceated?
That is nice to hear
>created?
top secret ;)
>health
That is nice to hear
>health?
That is nice to hear
>how
That is nice to hear
>do you like sports
I'm a very big fan of Cricket
>do you like sports
I'm a very big fan of Cricket
>do you like sports
I'm a very big fan of Cricket
>quit
It was nice talking to you. See you soon :)