How can I invoke a separate SPARQL file into a graph?

19 views
Skip to first unread message

Stephen H. Kim

unread,
Feb 19, 2020, 10:59:43 AM2/19/20
to rdflib-dev

Hi,

 

I am basically trying to have a giant text file with SPARQL code line by line. I want the transformation to be invoked into the graph line by line as well and run the transformation.

So far, I didnt have any luck. i've been reading up the documentation and modyfing my code accordingly but doc does not seem to mention invoking a separate file for SPARQL queries.... 

 

 

 

Here is the code I have been working on:

 

 

import os

with open('/cs/samirage/stephen/querystringtest.rq', 'r') as qbank:

    qbank = qbank.read()

 

g = rdflib.Graph()

g.parse('definitions/HR_Reference_Ontology.xml')

 

 

qres = g.query(qbank)  

 

## ParseException: Expected end of text (at char 32), (line:3, col:1) instead of 

 

 

for row in qres:

    print(row)

 

 

 

 

 

not sure if it is clear from the code, but i am trying to invoke the SPARQL code iteratively with the for loop, which will run the SPARQL queries into the graph.  

qbank is the file with SPARQL querie and the .xml is the graph model. 

Stephen H. Kim

unread,
Feb 19, 2020, 11:10:06 AM2/19/20
to rdflib-dev
pls help :(

Nicholas Car

unread,
Feb 24, 2020, 3:16:42 AM2/24/20
to rdfli...@googlegroups.com
Hi Stephen,

There’s not really enough information in the error you’ve given below for me to work out your problem. It looks like your posted text is cut-off.

I’m assuming you get no error when parsing the ontology itself, i.e. this line:

g.parse('definitions/HR_Reference_Ontology.xml')


The way you’ve posed the query to the graph is correct:

qres = g.query(qbank)  


The loop loos correct too:

for row in qres:

    print(row)

So, it looks like the only issue you have is that there’s an error with your SPARQL query. If you can post your query here, perhaps we can have a look at it. Just note though, actually working through your SPARQL query is a little off-topic for rdflid questions as it’s really about SPARQL, not the rdflib library.

Regards,

Nick





-- 
http://github.com/RDFLib
--- 
You received this message because you are subscribed to the Google Groups "rdflib-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rdflib-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rdflib-dev/3b8319fe-a6f2-47c6-8ae2-f348dac28fd1%40googlegroups.com.

______________________________________________________________________________________
 
Dr Nicholas Car
Data Systems Architect
SURROUND Australia Pty Ltd
Address P.O. Box 86, Mawson, Canberra ACT 2607
Phone  +61 477 560 177
Email  nichol...@surroundaustralia.com
Website  https://surroundaustralia.com

Enhancing Intelligence Within Organisations
delivering evidence that connects decisions to outcomes






Reply all
Reply to author
Forward
0 new messages