Search code examples
rdfsparqlontologylubm

Cannot extract RDF triple by locally defined predicate


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.


Solution

  • 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.