SPARQL examples – ask

Is the Amazon river longer than the Nile river?

You can also try this one against DBPedia…

PREFIX prop: <http://dbpedia.org/property/>
ASK
{
  <http://dbpedia.org/resource/Amazon_River> prop:length ?amazon .
  <http://dbpedia.org/resource/Nile> prop:length ?nile .
  FILTER(?amazon > ?nile) .
}

The answer is: false.

Note: The WHERE keyword is optional–not only in ASK queries but in all SPARQL queries.

Does a triple with the given subject URI exist?

ASK { <http://example.org/carbon/ldp/main/people> ?p ?o> }

Returns true or false.

Does Fred have grandchildren?

PREFIX: <http://bedrock/>  
ASK  
WHERE {  :fred :hasChild :?child . :?child :hasChild :?grandchild. }

Where :fred has any child, see if that child has any child identified by the placeholder, :?child, then use the value of that placeholder to ask whether or not that child itself also has a child, which will be the :?grandchild.