سؤال

Probably I just can't grasp some basic idea behind ontologies but here's my question. I'm trying to extract triples from an RDF storage (using 4store, but also tried XML ArmyKnife) with a SPARQL query specifying the predicate and get empty results.

To be sure I don't mess anything up with RDF syntax I use LUBM generated data (stripped down to an example-suitable size).

<?xml version="1.0" encoding="UTF-8" ?>
<rdf:RDF
  xml:base = "http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl"
  xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
  xmlns:owl="http://www.w3.org/2002/07/owl#"
  xmlns:ub="univ-bench.owl#"
>

<owl:DatatypeProperty rdf:ID="name">
  <rdfs:label>name</rdfs:label>
</owl:DatatypeProperty>

<owl:Class rdf:ID="Organization">
  <rdfs:label>organization</rdfs:label>
</owl:Class>

<owl:Class rdf:ID="University">
  <rdfs:label>university</rdfs:label>
  <rdfs:subClassOf rdf:resource="#Organization" />
</owl:Class>

<ub:University rdf:about="http://www.University0.edu">
   <ub:name>University0</ub:name>
</ub:University>

</rdf:RDF>

Then I run a query to see what triples my database actually contains after import:

SELECT * WHERE {?s ?p ?o} ORDERBY ?s

Here's the result:

<http://www.University0.edu>    <univ-bench.owl#name>   "University0"
<http://www.University0.edu>    <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>       <univ-bench.owl#University>
<http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#Organization>         <http://www.w3.org/2000/01/rdf-schema#label>    "organization"
<http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#Organization>     <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>       <http://www.w3.org/2002/07/owl#Class>
<http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#University>       <http://www.w3.org/2000/01/rdf-schema#subClassOf>       <http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#Organization>
<http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#University>       <http://www.w3.org/2000/01/rdf-schema#label>    "university"
<http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#University>       <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>       <http://www.w3.org/2002/07/owl#Class>
<http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#name>     <http://www.w3.org/2000/01/rdf-schema#label>    "name"
<http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#name>     <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>       <http://www.w3.org/2002/07/owl#DatatypeProperty>

It's clearly visible that I have <univ-bench.owl#name> predicate as a part of the first triple.

Nevertheless following query returns no results:

SELECT * WHERE {?s <univ-bench.owl#name> ?o}

I've tried dozens of combinations, with namespaces and without, but can't make it work. Can anyone explain why RDF engine doesn't find a predicate that's obviously there?

BTW, extracting the same triple with OBJECT="University0" works OK.

هل كانت مفيدة؟

المحلول

This is invalid:

xmlns:ub="univ-bench.owl#"

Namespace URIs must be absolute in RDF/XML. (They can be relative in other syntaxes like Turtle, but not in RDF/XML.) If your example is indeed generated straight by LUBM, then LUBM is broken. This should work:

xmlns:ub="http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#"

Then of course you need to match that URI in the SPARQL query like @RobV said.

نصائح أخرى

I suspect your problem is that you are not trying to match the correct URI in your query:

SELECT * WHERE {?s <univ-bench.owl#name> ?o}

Anything enclosed in angle brackets is treated as a URI and since you've used a relative URI the SPARQL processor is presumeably resolving it against some arbitrary base resulting in an absolute URI different from the one in your data thus your query won't match anything.

What you need to do is either specify the full URI like so:

SELECT * WHERE {?s <http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#name> ?o}

Or use a prefix like so:

PREFIX ub: <univ-bench.owl#>
SELECT * WHERE { ?s ub:name ?o }

If none of these are working then I suspect it is some issue with relative URIs. My advice would be never use relative URIs, always use absolute URIs wherever possible. If you must use relative URIs always specify a Base URI explicitly i.e. ensure your data used absolute URIs, reload it into your store and try again.

You can do this with xml:base="http://example.org" in RDF/XML or with BASE <http://example.org/> in SPARQL. If using 4store I believe their importer command line has arguments that can be used to set the default base URI for when none is specified.

The other thing you might want to do is to try putting your data into a different triple store and see if you experience the same behaviour, if you do then this would imply an issue with relative vs absolute URIs as I have suggested. If the other store answers the query fine that would suggest a possible bug with 4store in which case you should contact them on their mailing list - http://groups.google.com/group/4store-support

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top