forked from hannanabdul55/mobilechatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feature_query.py
executable file
·83 lines (83 loc) · 1.89 KB
/
feature_query.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
79
80
81
82
83
import re
from ner_client import *
def query_db_feature(d):
nr = NerClient("1PI11CS004","g08")
os = "Android"
org = "Samsung"
product=""
low_price = 0
max_price = 100000
family="None"
feature = "size"
if len(d["os_list"])>0:
os = d['os_list'][0]
if len(d["org"])>0:
org = d["org"][0]
elif os.lower()=="ios":
org="Apple"
elif os.lower() == "windows":
org="Nokia"
if len(d["family"])>0:
family = d["family"][0]
elif os=="Apple":
family="iPhone"
elif os=="Windows":
family="Lumia"
if len(d['family'])>0:
family = d['family'][0]
if len(d['feature'])>0 and d['feature']=='size':
feature = d['feature']
if feature=="size":
size_t = d['size_mentioned']
size_rel = d['query']
s = nr.get_products(org)
count = 0
result = []
family=="None"
if d['query']== 'less than':
if family=="None":
res = nr.get_spec(brand=org)
for i in res:
if i['category'] == 'Display':
try:
si = i['value'].split(',')[1].split()[0].strip()
si = float(si)
if int(size)<=int(si):
result.append(i['product'])
count+=1
except:
abcd =0
if count>20:
break
elif d['query']=='more than':
if family=="None":
res = nr.get_spec(brand=org)
for i in res:
if i['category'].lower() == 'display':
try:
si = i['value'].split(',')[1].split()[0].strip()
si = float(si)
#print si
if size>=int(si):
result.append(i['product'])
count+=1
except:
#print "error"
continue
if count>20:
break
else:
pass
#print d['start_price'] , d['end_price']
#print s
#print low_price
#print max_price
res_string = "The "+ org + " products satisfying the screen size features are :\n"
count = 1
#str(res)
for i in result:
res_string+=str(count) + ": " + i + "\n"
count+=1
if count>20:
break
return res_string