-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntentionDetection.py
More file actions
287 lines (181 loc) · 8.57 KB
/
IntentionDetection.py
File metadata and controls
287 lines (181 loc) · 8.57 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 30 20:10:11 2020
@author: Eduardo Vicente
"""
import random
from SPARQLProcessor import *
from OntoPT import *
import json
termin = ['ar','er','ir','or','ur']
question_words = ['que','quanto','quantos','cujo','cujos','quem','onde','quando','como','por','qual','quais','para','em']
verbs_quando = ['conseguir','poder','fazer','ver','mandar','começar',
'tentar','deixar','pedir','vir','continuar','pretender'
,'solicitar','comprar','encomendar','chegar','receber',
'despachar','enviar','acabar','cancelar','parar','sair']
verbs_search = ['encontrar','achar','descobrir','obter','conseguir','achar','ter','possuir','arranjar','sondar','intencionar','tencionar','pesquisar','rastrear','tentar','procurar','encontrar','encomendar','querer']
verbs_onde = ['localizar','ficar','pertencer','estar','manter','ser','existir','haver',
'conseguir','poder','fazer','ver','mandar','começar',
'tentar','deixar','pedir','vir','continuar','pretender'
,'solicitar','comprar','encomendar','chegar','receber','despachar','enviar','acabar',
'cancelar','parar','sair']
encomendas_prep_resp =['Iniciada a encomenda, o processo só pode ser cancelado via telefone com um Operador','Quando quiser!\nPara encomendar a peça de roupa desejada necessita apenas de carregar no botão sobre o produto que diz "Colocar no Carrinho"\nAutomaticamente o produto é colocado na lista de produtos a comprar no carrinho. Depois apenas tem de prosseguir normalmente com a encomenda!','Pode consultar todos os detalhes acerca das suas encomendas na Área Pessoal, ou então consultar os recibos eletrónicos via email','As encomendas chegam em 2-3 dias úteis, pode consultar e ver o trajeto da sua encomenda em Área Pessoal > Recibos/Encomendas']
encomendas2_prep_resp = ['Pode consultar-me a mim ou então utilizar a nossa ferramenta de pesquisa integrada com os mais sofisticados filtros']
localizacao_prep_resp = ['A loja encontra-se fisicamente instalada na Rua Adolfo Loureiro, Edificio nº 34','Estamos situados em Coimbra','Possuimos uma loja fisica situada em Coimbra e virtualmente neste dominio']
# verbo ter!!!
##PRONOMES ADJETIVOS INTERROGATIVOS
#que -> (que carro é aquele? ) -> SCONJ
#Quanto -> PRON
#cujo -> PRON
##PRONOMES SUBJANTIVOS INTERROGATIVOS
#QUEM -> PRON
#quem + ser;
#que -> (o que ...) PRON
#IR-RDF ->
#!IR-RDF ->
#quantos -> PRON
##ADVERBIOS INTERROGATIVOS
#onde (lugar)-> ADV
#IR-RDF -> onde + encontrar(*); onde + haver
#!IR-RDF -> onde + ser;
#onde + estar; onde + encontrar(*)
#onde + ficar; onde + manter;
#onde + existir; onde + localizar;
#onde + pertencer;
#quando (tempo)-> ADV
#IR-RDF ->
#!IR-RDF -> quando + sair; quando + receber;
#como (modo) -> ADV
#por que (razão/causa)-> ADV
#para que (objectivo/finalidade) -> SCONJ
##TARGET VERBOS
#procurar,encontrar,comprar,vender
#fabricar,produzir,custar,servir,haver
#recebe -> filtered , tag_pos
#NO RDF INFORMATION:
def no_IR_info(filtered,pos_tag):
return ""
def detect(filtered,pos_tag):
sin_loja = synsets("loja")
response = ""
#SPLIT INTO QUESTION-WORD AND ARGS
left = []
i=0
if len(filtered) > 0:
while i < len(filtered):
if filtered[i].lower() in question_words:
q_type = filtered[i].lower()
filtered.pop(i)
pos_tag.pop(i)
i = i + 1
# print(pos_tag)
# print(q_type)
if q_type == question_words[0]:
print("xD1")
elif q_type == question_words[1]:
print("xD2")
elif q_type == question_words[2]:
print("xD3")
elif q_type == question_words[3]:
print("xD4")
elif q_type == question_words[4]:
print("xD5")
elif q_type == question_words[5]:
print("xD6")
#ONDE
elif q_type == question_words[6]:
# print("xD8")
cancela = 0
local = 0
info_2 = 0
pesquisa = 0
#LOOK FOR VERBS
verb_aux = []
for i in range(len(filtered)):
v = pos_tag[i]
if v =='VERB':
v_aux = filtered[i]
if v_aux in verbs_onde[-4:]:
cancela = 1
elif v_aux in verbs_onde[0:4]:
print(verbs_onde[0:4])
local = 1
elif v_aux in verbs_search:
pesquisa = 1
else:
info_2 = 1
if cancela:
response = "" + encomendas_prep_resp[0]
elif local:
response = "" + random.choice(localizacao_prep_resp[:])
elif pesquisa:
store=0
non_verbs = []
for i in range(len(filtered)):
x = pos_tag[i]
print(x)
if x != 'VERB':
y = filtered[i].lower()
if y[-2:] not in termin:
print(y)
non_verbs.append(y)
print(non_verbs)
if y == "loja" or y in sin_loja:
store = 1
if store:
response = "" + random.choice(localizacao_prep_resp[:])
else:
print(non_verbs)
results = sparql_query(non_verbs)
response = results
# print("RDF Loading...")
elif info_2:
response = "" + random.choice(encomendas2_prep_resp[:])
else:
response = "Desculpe não entendi, ainda estou a aprender... :("
#QUANDO
elif q_type == question_words[7]:
# print("xD8")
cancela = 0
info_1 = 0
info_2 = 0
#LOOK FOR VERBS
verb_aux = []
for i in range(len(filtered)):
v = pos_tag[i]
if v =='VERB':
v_aux = filtered[i]
if v_aux in verbs_quando:
if v_aux in verbs_quando[-4:]:
cancela = 1
elif v_aux in verbs_quando[:5]:
print(verbs_quando[:5])
info_1 = 1
else:
info_2 = 1
if cancela:
response = "" + encomendas_prep_resp[0]
elif info_1:
response = "" + encomendas_prep_resp[1]
elif info_2:
response = "" + random.choice(encomendas_prep_resp[2:])
else:
response = "Desculpe não entendi, ainda estou a aprender... :("
elif q_type == question_words[8]:
print("xD9")
elif q_type == question_words[9]:
print("xD11")
elif q_type == question_words[10]:
print("xD12")
elif q_type == question_words[11]:
print("xD13")
elif q_type == question_words[12]:
print("xD14")
elif q_type == question_words[13]:
print("xD15")
else:
print("xDnull")
return response
else:
return
# print(detect(['Quando', 'chegar', 'pedir'], ['ADV', 'VERB', 'VERB']))