forked from adi0509/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat_bot_medium_code.py
More file actions
107 lines (94 loc) · 2.83 KB
/
Copy pathchat_bot_medium_code.py
File metadata and controls
107 lines (94 loc) · 2.83 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# -*- coding: utf-8 -*-
"""Chat_Bot_Medium_Code.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1tv1GbvUVjfzEmDCzSHbodJl5ErsHlM8x
"""
# Description: This is a chatbot program
#There are broadly two variants of chatbots: Rule-Based and Self learning.
#Rule-based approach, a bot answers questions based on some rules on which it is trained on
#Self learning bots are the ones that use some Machine Learning-based approach to chat
#import libraries
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 J.A.R.V.I.S like in Iron Man, but you can just call me Jarvis 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(.*)",
["randerson112358 created me using Python's NLTK library ","top secret ;)",]
],
[
r"(.*) (location|city) ?",
['Tokyo, Japan',]
],
[
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 (.*) (moviestar|actor|actress)?",
["Zendaya"]
],
[
r"quit",
["Bye for now. See you soon :) ","It was nice talking to you. See you soon :)"]
],
[
r"(.*)",
['That is nice to hear']
],
]
#This is a dictionary that contains a set of input values and its corresponding output values.
#It is an optional dictionary that you can use unless you want to use regular expressions.
reflections
#Create your own reflections
my_dummy_reflections= {
"go" : "gone",
"hello" : "hey there"
}
#default message at the start of chat
print("Hi, I'm Jarvis 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)
#chat._substitute('i am a programmer') #uncomment this line to see reflections example in action
#Start conversation
chat.converse()