sparqlredland

Rewrite SPARQL DESCRIBE query as CONSTRUCT


For some reason I can't issue DESCRIBE queries using Redland ( librdf.org ), is it possible to rewrite DESCRIBE as a CONSTRUCT QUERY for a given URI?

DESCRIBE <urn:my-uri>

I was thinking about writting it into something like this but I don't think this is valid in SPARQL

CONSTRUCT  { ?subject ?predicate ?object }
WHERE      { 
               { ?subject ?predicate ?object } 
               AND { 
                   { <urn:my-uri> ?predicate ?object } 
                   OR { ?subject <urn:my-uri> ?object } 
                   OR { ?subject ?predicate <urn:my-uri> } 
               } 
           }

Solution

  • Your are right that is not a valid SPARQL. The closest thing to your OR is UNION. And, there is no need for the AND operator, every triple pattern is by default a join not a union.

    For what you are trying is better to use a FILTER, like this example:

    CONSTRUCT  { ?subject ?predicate ?object }
    WHERE      { ?subject ?predicate ?object . 
                 FILTER (  ?subject = <urn:your_uri> || ?object = <urn:your_uri>)
               } 
    

    In some systems, for large knowledge bases, this query can be very expensive. And also if your database contains bNodes this query won't get the description of those nodes, it will get just the internal code. For most cases, running a DESCRIBE manually can't be accomplished with a single query and you'll have to implement some recursive logic in order to get all the information that describes a URI.