tags:

views:

45

answers:

3

Hi. I'm pretty new to SPARQL, OWL and Jena, so please excuse if I'm asking utterly stupid questions. I'm having a problem that is driving me nuts since a couple of days. I'm using the following String as a query for a Jena QueryFactory.create(queryString),

queryString = "PREFIX foaf:  <http://xmlns.com/foaf/0.1/&gt;"+
"PREFIX ho: <http://www.flatlandfarm.de/fhtw/ontologies/2010/5/22/helloOwl.owl#&gt;" +
"SELECT ?name ?person ?test ?group "+
"WHERE { ?person foaf:name ?name ; "+
"         a ho:GoodPerson ; "+
"         ho:isMemberOf ?group ; "+
"}";

Until this morning it worked as long as I only asked for properties from the foaf namespace. As soon as I asked for properties from my own namespace I always got empty results. While I was about to post this question here and did some final tests to be able to post it as precise as possible, it suddenly worked. So as I did not know what exactly to ask for anymore, I deleted my question before posting it. A couple of hours later I used Protege's Pellet plugin to create and export an inferred Model. I called it helloOwlInferred.owl and uploaded it to the directory on my server where helloWl.owl resided yet. I adjusted my method to load the inferred ontology and changed the above query so that the prefix ho: was assigned to the inferred ontology as well. At once, nothing worked any more. To be exact it was not nothing that worked any more but it was the same symptoms I had till this morning with my original query. My prefix did not work any more. I did a simple test: I renamed all the helloWorldInferred.owl files (the one on my server for the prefix and my local copy which I loaded) to helloWorld.owl. Strange enough that fixed everything.

Renaming it back to helloWorldInferred.owl broke everything again. And so on. What is going on there? Do I just need to wait a couple of weeks until my ontology gets "registered as a valid prefix"?

+1  A: 

The whole idea of prefixes and QNames is just to compress URIs to save space and improve readability, the most common issue with them is spelling errors either in the definitions themselves or in the QNames.

Most likely the prefix definition you are using in your query is causing URIs to be generated which don't match the actual URIs of properties in your ontology.

That being said your issue may be due to something with Jena so it may well be worth asking your question on the Jena Mailing List

RobV
+1  A: 

Maybe your OWL file contains the rdf:ID="something" construct (or some other form of relative URL, such as rdf:about="#something")?

rdf:ID and relative URLs are expanded into full absolute URLs, such as http://whatever/file.owl#something, by using the base URL of the OWL file. If the base URL is not explicitly specified in the file (using something like xml:base="http://whatever/file.owl"), then the location of the file on the web server (or in your file system if you load a local file) will be used as the base URI.

So if you move the file around or have copies in several locations, then the URIs in your file will change, and hence you'd have to change your SPARQL query accordingly.

Including an explicit xml:base, or avoiding relative URIs and rdf:ID, should fix the problem.

cygri
Thanks a lot. Your answer got me on the right track.
Tom
+1  A: 

It looks like this was caused by a bug (or a feature?) in Protege. When I exported the inferred ontology with a new name, Protege changed the definitions of xmlns(blank) and xml:base to the name of the new file, but it did not change the definition of the actual namespace.

xmlns="http://xyz.com/helloOwl.owl" =>  xmlns="http://xyz.com/helloOwlInferred.owl"
xml:base="http://xyz.com/helloOwl.owl" =>  xml:base="http://xyz.com/helloOwlInferred.owl"

xmlns:helloOwl="http://xyz.com/helloOwl.owl" =>  xml:base="http://xyz.com/helloOwl.owl"
<!ENTITY helloOwl "http://wxyz.com/helloOwl.owl#" > => <!ENTITY helloOwl "http://wxyz.com/helloOwl.owl#" >

Since I fixed that it seems to work.
My fault not having examined the the actual source with the necessary attention.

Tom