This is a follow-up question from How to prevent triples from getting mixed up while uploading to Dydra programmatically?
I've created a new graph using SPARQL CONSTRUCT query. I now want to iterate over it so that I can add the statements to an RDFlib graph and then insert the data into another triplestore. I have the following questions:
- If SPARQL CONSTRUCT returns a graph, do I still need to iterate over the statements and add them to an RDFlib graph? I probably need to do so to be able to insert each triple into a triplestore using a loop.
- How does one iterate over a graph resulting from SPARQL CONSTRUCT to retrieve the triples? The
'type'
of'output'
shows up as string.
This is my code:
sesameSparqlEndpoint = 'http://my.ip.ad.here:8080/openrdf-sesame/repositories/rep_name'
sparql = SPARQLWrapper(sesameSparqlEndpoint)
queryStringDownload = 'CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o FILTER REGEX(str(?s), "http")}'
dataGraph = Graph()
sparql.setQuery(queryStringDownload)
sparql.method = 'GET'
sparql.setReturnFormat(JSON)
output = sparql.query().convert()
# print output
#Print all statements in dataGraph
for stmt in output:
print stmt
This code just gives me a single column of characters from the triples.