-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
78 lines (56 loc) · 2.23 KB
/
Copy pathrun.py
File metadata and controls
78 lines (56 loc) · 2.23 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
import numpy as np
from sklearn.model_selection import LeaveOneOut
from sklearn.neighbors import KNeighborsClassifier
from sklearn import preprocessing
from sklearn.feature_extraction.text import TfidfVectorizer
intensao = []
frases = []
f = open("intensoes.txt", "r")
for x in f:
classe, texto = x.split(">>")
intensao.append(classe)
frases.append(texto.rstrip()) #rstrip remove o \n
#Converte as sentenças em BOW
vectorizer = TfidfVectorizer(sublinear_tf=True, max_df=0.5,strip_accents='unicode')
intensaoBow = vectorizer.fit_transform(frases)
intensaoNumpy = np.array(intensao)
leaveOneOut = LeaveOneOut()
leaveOneOut.get_n_splits(intensaoBow)
result = []
for train_index, test_index in leaveOneOut.split(intensaoBow):
X_train, X_test = intensaoBow[train_index], intensaoBow[test_index]
y_train, y_test = intensaoNumpy[train_index], intensaoNumpy[test_index]
#KNN
model = KNeighborsClassifier(n_neighbors=1)
model.fit(X_train,y_train)
resultado = model.predict(X_test)[0]
result.append(resultado)
import telepot
apikey = "1765992736:AAFJGuA668ycHfIwC_LSQfEUjqIopggp7iY"
tele = telepot.Bot(apikey)
def responder(userId, username, intensao):
if intensao == 'saudacao':
tele.sendMessage(userId, "Olá, "+username+"!")
elif intensao == 'despedida':
tele.sendMessage(userId, "Até mais, "+username)
elif intensao == 'ajuda':
tele.sendMessage(userId, "No que eu posso te ajudar?")
elif intensao == 'agradecimento':
tele.sendMessage(userId, "De nada! Se precisar estamos aí o/")
elif intensao == 'agendaDoDia':
tele.sendMessage(userId, "Essa é sua agenda do dia")
elif intensao == 'agendaSemanal':
tele.sendMessage(userId, "Essa é sua agenda da semana")
elif intensao == 'agendaMensal':
tele.sendMessage(userId, "Essa é sua agenda do mês")
elif intensao == 'happyHour':
tele.sendMessage(userId, "Será sexta-feira, 26/03, às 16:30hs. #Sextou")
else:
tele.sendMessage(userId, "Sinto mt,"+username+". Não entendi o que vc disse. Me explica de outra forma")
def receberMensagem(msg):
inst = vectorizer.transform([msg['text']])
intensao = model.predict(inst)
responder(msg['from']['id'], msg['from']['first_name'], intensao[0])
tele.message_loop(receberMensagem)
while True:
pass