-
Notifications
You must be signed in to change notification settings - Fork 0
/
compose_qry.py
39 lines (31 loc) · 1.2 KB
/
compose_qry.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
"""
This module modifies existing SPARQL queries
- to retrieve relevant EUROVOC concepts in legal in-force documents
- to retrieve other relevant documents
"""
import os
def change_eurovoc(sql_path, code):
'''
replace eurovoc code within SPARQL query that varies based on the eurovoc code
'''
with open(sql_path, 'r') as file:
sparql_query = file.read()
print('SPARQL_QUERY:', sparql_query)
sparql_query = sparql_query.replace('EUROVOC_CODE', code)
print('SPARQL_QUERY:', sparql_query)
return sparql_query
def get_qry(query_name, code=None):
'''
Choose the type of query in sparql_queries folder
- all-eurovoc-concepts: retrieve all EUROVOC concepts
- all-eu-treaties: retrieve all EU treaties
- legal-in-force-EUROVOC: retrieve all EU legislation in force using EUROVOC concepts
'''
sql_path = '/Users/yun/Dev/humanet3/human-centered-eu/queries/sparql_queries/' + query_name
qry_name = os.path.basename(sql_path).replace('.rq', '-')
if code:
sparql_query = change_eurovoc(sql_path, code)
else:
with open(sql_path, 'r') as file:
sparql_query = file.read()
return sparql_query, qry_name