forked from cmo/triple-tools
59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
import argparse
|
|
|
|
import rdflib
|
|
from rdflib import Graph
|
|
|
|
q0 = """
|
|
PREFIX dlrelationsmx: <https://concepts.datalad.org/s/relations-mixin/unreleased/>
|
|
PREFIX frapo: <http://purl.org/cerif/frapo/>
|
|
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
|
PREFIX xyzra: <https://concepts.datalad.org/s/demo-rse-group/unreleased/>
|
|
|
|
|
|
SELECT ?s ?ad WHERE {
|
|
?s rdf:type xyzra:XYZCompetition .
|
|
?s dlrelationsmx:kind frapo:FundingProgramme .
|
|
?s xyzra:application_deadline ?ad .
|
|
} ORDER BY ?ad
|
|
"""
|
|
|
|
q2 = """
|
|
PREFIX dlrelationsmx: <https://concepts.datalad.org/s/relations-mixin/unreleased/>
|
|
PREFIX dlprovmx: <https://concepts.datalad.org/s/prov-mixin/unreleased/>
|
|
PREFIX frapo: <http://purl.org/cerif/frapo/>
|
|
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
|
PREFIX xyzra: <https://concepts.datalad.org/s/demo-rse-group/unreleased/>
|
|
|
|
|
|
SELECT ?competition ?person WHERE {
|
|
?competition rdf:type xyzra:XYZCompetition .
|
|
?project dlprovmx:informed_by ?link .
|
|
?link rdf:type dlprovmx:Communication .
|
|
?link dlrelationsmx:roles frapo:FundingApplication .
|
|
?link rdf:object ?competition .
|
|
?project dlprovmx:associated_with ?link2 .
|
|
?link2 rdf:object ?person
|
|
} ORDER BY ?ad
|
|
"""
|
|
|
|
|
|
argument_parser = argparse.ArgumentParser()
|
|
argument_parser.add_argument('input_file')
|
|
#argument_parser.add_argument('query', nargs=1)
|
|
|
|
arguments = argument_parser.parse_args()
|
|
|
|
|
|
def show_query_result(r, vars: list[str]):
|
|
for row in r:
|
|
# For select queries, the Result object is an iterable of ResultRow
|
|
# objects.
|
|
assert isinstance(row, rdflib.query.ResultRow)
|
|
for var in vars:
|
|
print(f'{var}:', row[var])
|
|
|
|
|
|
g = Graph()
|
|
g.parse(arguments.input_file)
|
|
show_query_result(g.query(q0), ['s', 'ad'])
|
|
show_query_result(g.query(q2), ['competition', 'person'])
|