-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.py
More file actions
152 lines (130 loc) · 3.66 KB
/
Copy pathstart.py
File metadata and controls
152 lines (130 loc) · 3.66 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import nltk
import json
from nltk.chat.util import Chat, reflections
import numpy as np
import random
import string # to process standard python strings
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
import copy
reflections = {
"i am" : "you are",
"i was" : "you were",
"i" : "you",
"i'm" : "you are",
"i'd" : "you would",
"i've" : "you have",
"i'll" : "you will",
"my" : "your",
"you are" : "I am",
"you were" : "I was",
"you've" : "I have",
"you'll" : "I will",
"your" : "my",
"yours" : "mine",
"you" : "me",
"me" : "you"
}
my_dummy_reflections= {
"go" : "gone",
"hello" : "hey there"
}
pairs = [
[
r"my name is (.*)",
["Hello %1, How are you today ?,Hi there, how can I help?",]
],
[
r"(.*) created ?",
["XXYY created me using Python's NLTK library ","top secret ;)",]
],
[
r"what is your name ?",
["My name is Chatty and I'm a chatbot ?",]
],
[
r"how are you ?",
["I'm doing good\nHow about You ?",]
],
[
r"sorry (.*)",
["Its alright","Its OK, never mind",]
],
[
r"i'm (.*) doing good",
["Nice to hear that","Alright :)","dont repete again :)",]
],
[
r"hi|hey|hello",
["Hello", "Hey there",]
],
[
r"(.*) age?",
["I'm a computer program dude\nSeriously you are asking me this?",]
],
[
r"what (.*) want ?",
["Make me an offer I can't refuse",]
],
[
r"(.*) (location|city) ?",
['Ch, Tam',]
],
[
r"how is weather in (.*)?",
["Weather in %1 is awesome like always","Too hot man here in %1","Too cold man here in %1","Never even heard about %1"]
],
[
r"i work in (.*)?",
["%1 is an Amazing company, I have heard about it. But they are in huge loss these days.",]
],
[
r"(.*)raining in (.*)",
["No rain since last week here in %2","Damn its raining too much here in %2"]
],
[
r"how (.*) health(.*)",
["I'm a computer program, so I'm always healthy ",]
],
[
r"(.*) (sports|game) ?",
["I'm a very big fan of Football",]
],
[
r"who (.*) sportsperson ?",
["Messy","Ronaldo","Roony"]
],
[
r"fine (.*) you ?",
["whats new?","go on ask question?","I dont think it valid, do you?"]
],
[
r"who (.*) (moviestar|actor)?",
["Brad Pitt"]
],
[
r"quit",
["BBye take care. See you soon :) ","It was nice talking to you. See you soon :)"]
],
]
def convertToPair(fileName):
mylist=[]
mylistPatterns =[]
with open("intents.json") as file:
data = json.load(file)
for intent in data["intents"]:
mylistPatterns.extend(intent["patterns"])
mylistPatterns.append(intent["responses"])
mylist.append(mylistPatterns.copy())
mylistPatterns.clear()
#for k, v in mylist:
# print(k,"=:=", v)
return mylist
def chatty():
myResultlist=convertToPair("intents.json")
print("Hi, I'm Chatty and I chat alot ;)\nPlease type lowercase English language to start a conversation. Type quit to leave ") #default message at the start
#chat = Chat(tuples, reflections)
chat = Chat(myResultlist, reflections)
chat.converse()
if __name__ == "__main__":
chatty()