-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpattern.py
160 lines (137 loc) · 7.58 KB
/
pattern.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
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
import math
from rate_price_check import rate_check
from rate_price_check import price_check
from database_importing import dict_create
from output_str_fin import otpt
di = dict_create()
def match_code(i,min_p,max_p,rating,tpe):
outpt = {}
if min_p<= (di[i]['Price'])<= max_p:
if di[i]['Rating']>= rating:
if tpe == "Dish":
outpt[len(outpt)+1] = [di[i]['Canteen'], str(di[i]['Rating']), str(di[i]['Price'])]
elif tpe == "Canteen":
outpt[len(outpt)+1] = [di[i]['Dish'], str(di[i]['Rating']), str(di[i]['Price'])]
elif tpe == "Cuisine":
outpt[len(outpt)+1] = [di[i]['Dish'], str(di[i]['Rating']), str(di[i]['Price']), di[i]['Canteen']]
return outpt
def matching_code(i,min_p,max_p,rating,tpe, search_type, each_chr):
if min_p<= (di[i]['Price'])<= max_p:
if di[i]['Rating']>= rating:
match = 0
spl = list(di[i][search_type])
if len(spl)< len(each_chr):
maxi= len(spl)
else:
maxi = len(each_chr)
for x in range(maxi):
if each_chr[x] == spl[x]:
match +=1
if len(each_chr)>5:
if match>=math.floor(0.7*len(each_chr)):
matching.append(di[i][search_type])
else:
if match>=3:
matching.append(di[i][search_type])
def search(inpt,rating_str,price, veg, halal, search_type):
veg = veg.upper()
halal = halal.upper()
if search_type == 'Dish':
tpe = 'Dish'
elif search_type == 'Canteen':
tpe = 'Canteen'
elif search_type == 'Cuisine':
tpe = 'Cuisine'
while True:
findfood = inpt.upper()
output_str=""
rating=int(rating_str)
distinct_match = []
exact_match = 0
rating_checked = rate_check(rating_str)
try:
rating = int(rating_checked)
except ValueError:
return rating_checked
try:
min_p,max_p = price_check(price)
except ValueError:
return price_check(price)
matching=[]
for i in range(0,len(di)):
if di[i][tpe] == findfood:
exact_match += 1
check_veg = (str(di[i]["Vegetarian"])).upper()
check_halal = (str(di[i]["Halal"])).upper()
if veg == "TRUE" and halal=="TRUE":
if veg == check_veg:
if halal == check_halal:
outpt = match_code(i,min_p,max_p,rating,tpe)
elif veg == "TRUE" and halal=="FALSE":
if veg == check_veg:
outpt = match_code(i,min_p,max_p,rating,tpe)
elif veg == "FALSE" and halal=="TRUE":
if halal == check_halal:
outpt = match_code(i,min_p,max_p,rating,tpe)
elif veg == "FALSE" and halal=="FALSE":
outpt = match_code(i,min_p,max_p,rating,tpe)
if outpt == None:
print ("None")
if len(outpt) == 0 and exact_match != 0:
return "\nNo "+ tpe+ " of this choice found in the given rating and price range"
elif len(outpt) == 0:
for x in range(len(di)):
check_veg = (str(di[x]["Vegetarian"])).upper()
check_halal = (str(di[x]["Halal"])).upper()
if veg == check_veg:
if halal == check_halal:
if min_p<= (di[x]['Price'])<= max_p:
if di[x]['Rating']>= int(rating):
split_chr = di[x][search_type].split()
for i in range(len(split_chr)):
if split_chr[i] == findfood:
matching.append(di[x][search_type])
each_chr = list(findfood)
for i in range(0, len(di)):
check_veg = (str(di[i]["Vegetarian"])).upper()
check_halal = (str(di[i]["Halal"])).upper()
if veg == "TRUE" and halal=="TRUE":
if veg == check_veg:
if halal == check_halal:
matching_code(i,min_p,max_p,rating,tpe,search_type, each_chr)
elif veg == "TRUE" and halal=="FALSE":
if veg == check_veg:
matching_code(i,min_p,max_p,rating,tpe,search_type, each_chr)
elif veg == "FALSE" and halal=="TRUE":
if halal == check_halal:
matching_code(i,min_p,max_p,rating,tpe,search_type, each_chr)
elif veg == "FALSE" and halal=="FALSE":
matching_code(i,min_p,max_p,rating,tpe,search_type, each_chr)
if len(matching) == 0:
return "\nNo "+tpe+" of this choice found in the given rating and price"
else:
output_str += "Did you mean "
for i in range(len(matching)-1):
if matching[i] in distinct_match:
continue
else:
output_str += matching[i]
output_str += ","
distinct_match.append(matching[i])
if matching[len(matching)-1] in distinct_match:
output_str += "?"
else:
output_str += "and "
output_str += matching[len(matching)-1]
return output_str
elif len(outpt)==1:
if search_type=='Canteen':
return ("You can find " + outpt[1][0] +" at "+ inpt + " with these specifications.")
elif search_type =='Dish':
return("You can find "+ inpt + " at " + outpt[1][0] + " with these specifications.")
elif search_type == 'Cuisine':
return ("In "+ inpt+ " cuisine, you can find "+outpt[1][0]+" at "+outpt[1][3] + " with these specifications.")
else:
print ("else")
output_str = otpt(search_type ,outpt,inpt)
return output_str