Skip to content

Commit 27ea201

Browse files
committed
RPQ generation is improved. Queries are generated to files in common format.
1 parent 029beda commit 27ea201

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

tools/gen_RPQ/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
First step is edges investigation
22
* Run ```python3 RDF_edge_stat.py my_rdf.rdf my_config``` . Mapping from URIs to integers will be saved to my_config. You can use tid config for RDf to triples convertion using RDF_to_triple tool. Numbers of edges labelled with URIs will be printed in concole.
3-
* Run ```python3 gen.py my_config n_URIs q_for_each_tpl```, where ```my_config``` is a config generated at the previous step, first ```n_URIs``` labels from config will be used to generate queryes, ```q_for_each_tpl``` queryes will be generated for each template.
3+
* Run ```python3 gen.py my_config n_URIs q_for_each_tpl result_root_dir```, where ```my_config``` is a config generated at the previous step, first ```n_URIs``` labels from config will be used to generate queryes, ```q_for_each_tpl``` queryes will be generated for each template.

tools/gen_RPQ/gen.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,41 @@
1-
import numpy,sys
1+
import numpy, sys, os, shutil
22

3-
templates = [(1,'%s*'), (2,'%s %s*'), (3,'%s %s* %s*'), (2,'(%s | %s)*'), (3,'(%s | %s | %s)*'), (4,'(%s | %s | %s | %s)*'),
4-
(5,'(%s | %s | %s | %s | %s)*'), (3,'%s %s* %s'), (2,'%s* %s*'), (3,'%s %s %s*'), (2,'%s? %s*'),
5-
(2,'(%s | %s)+'), (3,'(%s | %s | %s)+'), (4,'(%s | %s | %s | %s)+'), (5,'(%s | %s | %s | %s | %s)+'),
6-
(3,'(%s | %s) %s*'), (4,'(%s | %s | %s) %s*'), (5,'(%s | %s | %s | %s) %s*'), (6,'(%s | %s | %s | %s | %s) %s*'),
7-
(2,'%s %s'), (3,'%s %s %s'), (4,'%s %s %s %s'), (5,'%s %s %s %s %s')]
3+
templates = [(1, '%s*', 'q1'), (2, '%s %s*', 'q2'), (3, '%s %s* %s*', 'q3'),
4+
(2, '(%s | %s)*' , 'q4_2'), (3, '(%s | %s | %s)*', 'q4_3'), (4, '(%s | %s | %s | %s)*', 'q4_4'), (5, '(%s | %s | %s | %s | %s)*', 'q4_5'),
5+
(3, '%s %s* %s', 'q5'), (2, '%s* %s*', 'q6'), (3, '%s %s %s*', 'q7'), (2, '%s? %s*', 'q8'),
6+
(2, '(%s | %s)+', 'q9_2'), (3, '(%s | %s | %s)+', 'q9_3'), (4, '(%s | %s | %s | %s)+', 'q9_4'), (5, '(%s | %s | %s | %s | %s)+', 'q9_5'),
7+
(3, '(%s | %s) %s*', 'q10_2'), (4, '(%s | %s | %s) %s*', 'q10_3'), (5, '(%s | %s | %s | %s) %s*', 'q10_4'), (6, '(%s | %s | %s | %s | %s) %s*', 'q10_5'),
8+
(2, '%s %s', 'q11_2'), (3, '%s %s %s', 'q11_3'), (4, '%s %s %s %s', 'q11_4'), (5, '%s %s %s %s %s', 'q11_5')]
89

910
def gen (tpl, n, lst, k):
1011
res = set()
1112
while (len(res) < n):
1213
perm = numpy.random.permutation(lst)
13-
res.add(tpl % tuple(perm[0:k]))
14+
res.add(((tpl % tuple(perm[0:k])),tuple(perm[0:k])))
1415
return res
1516

1617
def gen_from_config(config, num_of_lalbels, num_of_queries):
1718
lbls = [ l.split(' ')[1].rstrip() for l in open(config,'r').readlines()]
18-
return [gen (tpl[1], num_of_queries, lbls[0:num_of_lalbels], tpl[0]) for tpl in templates]
19+
return [(tpl[2], gen (tpl[1], num_of_queries, lbls[0:num_of_lalbels], tpl[0])) for tpl in templates]
20+
21+
def print_qs (qs, root_dir):
22+
for qd in qs:
23+
path = os.path.join(root_dir, qd[0])
24+
if os.path.exists(path):
25+
shutil.rmtree(path)
26+
os.mkdir(path)
27+
i = 0
28+
for q in qd[1]:
29+
with open(os.path.join(path,str(i)),'w') as out:
30+
out.write('S\n')
31+
out.write(' '.join(q[1]) + '\n')
32+
out.write('S -> ' + q[0] + '\n')
33+
i = i + 1
1934

2035
r = gen_from_config(sys.argv[1],int(sys.argv[2]),int(sys.argv[3]))
2136

37+
print_qs(r, sys.argv[4])
38+
2239
for s in r:
2340
for q in s:
2441
print(q)

0 commit comments

Comments
 (0)