2

I have the following Query

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?type
WHERE
{
   {
      SELECT *
      WHERE
      {
           ?x rdfs:subClassOf ?type .
      }
   }
   OPTION (TRANSITIVE, t_distinct, t_in (?x), t_out (?type) ) .
   FILTER (?x = <http://dbpedia.org/ontology/Hospital>)
}

It works fine when i send it to Virtuoso endpoint but does not work on my Jena instance. In specific i get the following error:

INFO  [1] 400 Parse error: 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?type
WHERE
{
   {
      SELECT *
      WHERE
      {
           ?x rdfs:subClassOf ?type .
      }
   }
   OPTION (TRANSITIVE, t_distinct, t_in (?x), t_out (?type) ) .
   FILTER (?x = <http://dbpedia.org/ontology/Hospital>)
}
Lexical error at line 12, column 39.  Encountered: " " (32), after : "OPTION" (17 ms)

In case this a Virtuoso specific function, I would appreciate to know an equivalent for this query that would work with *Jena/Standard SPARQL). The expected output should be:

http://dbpedia.org/ontology/Building
http://dbpedia.org/ontology/ArchitecturalStructure
http://dbpedia.org/ontology/Place
http://dbpedia.org/ontology/d0:Location

which represents all superclasses for "Hospital"

alexandria
  • 105
  • 7

1 Answers1

5

This is the expected behavior. This part of the query:

OPTION (TRANSITIVE, t_distinct, t_in (?x), t_out (?type) ) 

is not standard SPARQL 1.1 but it is a Virtuoso specific extension.

Jena is a SPARQL 1.1 compliant implementation.

The following query does the same thing using standard SPARQL 1.1 syntax, and should work with both Fuseki and Virtuoso (just tested on the dbpedia endpoint and got the same result):

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?type
WHERE
{
  {
   SELECT *
   WHERE
    {
       ?x rdfs:subClassOf+ ?type .
    }
  }
  FILTER (?x = <http://dbpedia.org/ontology/Hospital>)
}

The feature used is the "property path".

See http://www.w3.org/TR/sparql11-query/

enridaga
  • 631
  • 4
  • 9
  • 5
    If you are using Jena to send a query with Virtuoso-specific features, you need to direct create a QueryEngineHTTP (which is a QueryExecution) and provide just the 2 strings, endpoint and query string. Otherwise, Jena validates the query locally but it isn't valid SPARQL hence it fails. – AndyS Sep 24 '14 at 10:48
  • Thank you enridago and @AndyS. This guy [http://blog.pingoured.fr/index.php?post/2011/10/11/Jena%2C-virtuoso-and-option-transitive] claimed it worked for him using QueryEngineHTTP. This is why i cropped out what enridaga suggested, though i know its Virtuoso specific. Unfortunately the suggested code did not run for me and Fuseki threw back the same exception so im guessing this matches what both of you indicated. Is there a way to rewrite this query to work with Jena ? – alexandria Sep 24 '14 at 11:11
  • Can you edit your question describing what kind of result do you expect? Is it only transitivity on rdfs:subClassOf? If this is the case you can use a property path, that is a SPARQL 1.1 feature. – enridaga Sep 24 '14 at 12:26
  • Iv expanded the question to inquire about the equivalent query – alexandria Sep 24 '14 at 13:05
  • And I have expanded the answer too. Accept? :) – enridaga Sep 24 '14 at 16:29
  • Thank you enridaga ! I will need to figure out how to import the OWL to my Jena DBPedia instance to test it locally then =) – alexandria Sep 24 '14 at 20:24