This repository has been archived by the owner on Oct 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathChatbot.py
78 lines (77 loc) · 2.25 KB
/
Chatbot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#NLTK library is Natural Language Toolkit that is used for building Python programs that work with human language data for applying in statistical natural language processing (NLP)
#nltk.chat.util --> used for chatting utilities
#Reflections is a dictionary that when a value in a regular expression group matches a key in the dictionary it will output the value in the response
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 Nagato, 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(.*)",
["Davjot Singh 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"(.*)(Anime|game|Manga)(.*)",
["I'm a very big fan of Anime",]
],
[
r"who (.*) (Manga|Anime)?",
["Demon Slayer"]
],
[
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 Nex 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()