forked from naru-project/naru
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueries.py
56 lines (46 loc) · 1.59 KB
/
queries.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
"""Query Formalization"""
import os
import csv
DATA_PATH = '/var/tmp/cardDB/data'
def ParseInteger(lrange, rrange):
# TODO
if lrange == 'MAX' or rrange == 'MIN':
return None
assert lrange != 'MAX' and rrange != 'MIN', (lrange, rrange)
if lrange == 'MIN' and rrange == 'MAX':
return None
elif lrange == 'MIN':
return '<=', int(float(rrange))
elif rrange == 'MAX':
return '>=', int(float(lrange))
elif lrange == rrange:
return '=', int(float(lrange))
lrange = int(float(lrange))
rrange = int(float(rrange))
assert lrange < rrange, (lrange, rrange)
return '[]', (lrange, rrange)
def LoadForestQueries(filename='query'):
csv_file = os.path.join(DATA_PATH, 'forest', '{}.csv'.format(filename))
print('load from query file: {}'.format(csv_file))
num_attr = 10
queries = []
with open(csv_file, 'r') as infile:
reader = csv.reader(infile, delimiter=',', quotechar='|')
for query in reader:
# print(query)
col_idxs = []
ops = []
vals = []
for i in range(num_attr):
# all values in forests are integers
parsed = ParseInteger(query[i*2], query[i*2+1])
if parsed is None:
continue
else:
t_op, t_val = parsed
col_idxs.append(i)
ops.append(t_op)
vals.append(t_val)
queries.append((col_idxs, ops, vals))
print('{} queries in total'.format(len(queries)))
return queries