-
Notifications
You must be signed in to change notification settings - Fork 2
/
wildcard.py
67 lines (50 loc) · 1.47 KB
/
wildcard.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
import json
def wildcardProcessing(query) :
final_list = []
parts = query.split("*")
if len(parts) == 3:
case = 4
elif parts[1] == '':
case = 1
elif parts[0] == '':
case = 2
elif parts[0] != '' and parts[1] != '':
case = 3
if case == 4:
if parts[0] == '':
case = 1
f = open('permute.json')
permuterm = json.load(f)
f.close()
def prefix_match(term, prefix):
term_list = []
for tk in term.keys():
# if tk.startswith(prefix):
# term_list.append(term[tk])
if tk.startswith(prefix):
# print(prefix, tk)
if term[tk] not in term_list:
term_list.append(term[tk])
return term_list
if case == 1:
query = parts[0]
elif case == 2:
query = parts[1] + "$"
elif case == 3:
query = parts[1] + "$" + parts[0]
elif case == 4:
queryA = parts[2] + "$" + parts[0]
queryB = parts[1]
def intersection(lst1, lst2):
lst3 = [value for value in lst1 if value in lst2]
return lst3
if case != 4:
final_list = prefix_match(permuterm,query)
elif case == 4:
# queryA Z$X
term_listA = prefix_match(permuterm,queryA)
#print(term_list)
# queryB Y
term_listB = prefix_match(permuterm,queryB)
final_list = intersection(term_listA, term_listB)
return final_list