SPARQL Examples – Ask

Posted on Aug 31, 2017 (last modified May 7, 2021)

Is the Amazon river longer than the Nile river?

You can also try this one against DBPedia…

PREFIX prop: <> ASK { <> prop:length ?amazon . <> 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 { <> ?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.