Re: SPARQL queries: predicates, dumps, abouts etc

conor dowling wrote:

> Background: I want to migrate a factlog 
> ( to remote, 
> granular queries and away from monolithic RDF XML files. As I migrate 
> from my old XUL template queries to SPARQL, some questions popped up. I 
> think they are of general interest. I hope so anyway.
> 1) predicates as variables and dumping/discovery:
> Let's say running the following
>     SELECT *
>     WHERE {?person foaf:name ?name ; foaf:mbox ?mbox}
> gets results like
> [:p1 "joe" <>]
> [:p2 "fred" <>]
> etc
> Consider:
>     SELECT ?subject ?predicate WHERE { ?subject ?predicate ?object }
> Do I get a dump of all of the predicates supported by each and every 
> resource in a graph?


Minor proviso: the answer is yes if by 'supported' you mean that a
statement matching the pattern is present in the graph.

> i.e. something like
> [:p1 foaf:name]
> [:p1 foaf:mbox]
> [:p2 foaf:name]
> [:p2 foaf:mbox]
> etc?

That is correct.

> If so, does the following retrieve all the values of all the predicates, 
> in other words dump the graph?
>     SELECT *
>     WHERE { ?subject ?predicate ?object }
> i.e. something like
> [:p1 foaf:name "joe"]
> [:p1 foaf:mbox <>]
> etc

Yes. Although if what you want is a dump of the graph in triple-form,
you would be better off using a CONSTRUCT query.

> A variation of this, where you set the subject to :p1 would dump all of 
> the values of its predicates ... true?


> 2) rdf:about value and value of "?subject"
> # can I get the "rdf:about" from every resource
> PREFIX rdf:    <>
> SELECT ?about
> WHERE { ?subject rdf:about ?about }


rdf:about is not an actual property, but is simply a bit of syntax in
the RDF/XML serialization that is used to denote the subject of a
triple. It does not occur in the RDF graph and can not be queried
through SPARQL (or any other RDF query language that I know of).

For example:

  <rdf:Description rdf:about="#myCar">

The 'rdf:about' attribute is not a property, it just denotes that
"myCar" is the subject of the RDF triple (:myCar ex:hasColor "red").

> is this equivalent to (presuming all resources have abouts and aren't 
> blank)?
> SELECT ?subject
> The subject variable is bound to an about uri value OR if blank, a 
> unique id, scoped to the result. Is that right?

Not quite. See above.

> 3) Types - just like any other predicate?
>     SELECT *
>     WHERE { ?subject rdf:type ?type }
> will give me all of the types of all of the resources - right?

Yes. Although you should keep in mind that SPARQL itself makes no
guarantees as to how much of the RDF(S) semantics is used. That is up
to the implementation. So a very naive SPARQL implementation will only
return the types of the resources for which this type is explicitly
defined in the data, other implementations, that do RDF(S) inferencing
will return all types for all resources.

> [:p1 foaf:Person]
> [:p1 t3p:Gamekeeper] ... it's just an example!
> i.e. all the values of type for resources.
> 4) objects become subjects: arcs in as well as arcs out are supported
> Let's say "Event" resources reference "Person" resources using a 
> predicate "t3p:involved". So will ...
> SELECT ?person ?name ?eventName
>   { ?person foaf:name ?name .
>     ?event t3p:involved ?person . <----- subject "person" becomes object
>     ?event foaf:name ?eventName }
> give me people names with the names of all of their events?
> [:people/p1 "joe" "Joe goes to Cairo"]
> [:people/p1 "joe" "Joe does Jordan"]
> etc


> Thx in advance for any misconceptions cleared up ...

No problem. I hope this was helpful to you.


Jeen Broekstra          Aduna BV
Knowledge Engineer      Julianaplein 14b, 3817 CS Amersfoort        The Netherlands
tel. +31 33 46599877

Received on Monday, 9 May 2005 10:55:14 UTC