Example SPARQL Queries


In this example we will query the Linked Open Data Cloud for occurrence records for the Monarch Butterfly Danaus plexippus.

Occurrence records have been created that contain a particular pattern of subject predicate and object triples.

<Occurrence> <txn:occurrenceHasSpeciesConcept> <SpeciesConcept>

Since we are interested in occurrences of the Monarch Butterfly, we will use that URI as the object.

<Occurrence> <txn:occurrenceHasSpeciesConcept> <MonarchSpeciesConcept>

This leaves the occurrence URI's as the unknown "subject" that we will be querying for.

We will be asking the server to find those URI's that match a pattern, and then return the information at each of these URI's.

The URI's that the server needs to find are those that are the subject of triples which contain a predicate of txn:occurrenceHasSpeciesConcept and a object of "Monarch Butterfly Species Concept"

The server will find the matching occurrence URI's and then return the information associated with each URI, through the "DESCRIBE" function.

Query for Species Occurrence Records

The long URI's are "prefixed" to make the query itself more readable. The "Monarch_Butterfly" is our short name the Monarch Butterfly. The "?x" variable is what we are querying for - the occurrence URI's. The DESCRIBE function is used to return information about each URI - which in this case are observations.

PREFIX txn: <http://lod.taxonconcept.org/ontology/txn.owl#>
PREFIX Monarch_Butterfly: <http://lod.taxonconcept.org/ses/mCcSp.html#Species>

?x txn:occurrenceHasSpeciesConcept Monarch_Butterfly:.

If you click on the query link below,  URIBurner will process the query against the LOD cloud and should return two occurrence records. Since these occurrence records include a longitude and latitude in the geo vocabulary, this Virtuoso-based server displays the returned records on a GoogleMap.

Run Live Query via URIburner


Query for Species Images

The following query will return the image name and contributor of those images which have been tagged as being images of the Butterfly Vanessa cardui

PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dcterms:<http://purl.org/dc/terms/>
PREFIX Vanessa_cardui_Image: <http://lod.taxonconcept.org/ses/dwAmr.html#Image>

select distinct ?s, ?s as ?image, ?creator where {
?s rdf:type Vanessa_cardui_Image:.
?s dcterms:creator ?creator}
limit 10

Run Live Query via URIburner

Query for species in the Order Carnivora expected in Wisconsin

 This query will return the family, genus, scientific name, and thumbnail image for species in the Order Carnivora that are expected in Wisconsin. Since there are some species that do not have thumbnails the optional syntax is used. This will return the species even if there is not a thumbnail image.

PREFIX txn:        <http://lod.taxonconcept.org/ontology/txn.owl#>
PREFIX txnkb:      <http://lod.taxonconcept.org/ontology/void.rdf#TaxonConcept>
PREFIX rdf:        <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dcterms:    <http://purl.org/dc/terms/>
PREFIX wisconsin:  <http://sws.geonames.org/5279468/>
PREFIX carnivora:  <http://purl.uniprot.org/taxonomy/33554> 

select distinct ?s, ?o as ?image, ?order, ?family, ?genus, ?sciname, ?cname, ?author where {
 ?s rdf:type txn:SpeciesConcept.
 ?s dcterms:isPartOf txnkb:.
 ?s txn:uniprotOrder carnivora:.
 ?s txn:isExpectedIn wisconsin:.
 ?s txn:family  ?family.
 ?s txn:genus   ?genus.
 ?s txn:scientificName   ?sciname.
 ?s txn:authority ?author.
 ?s txn:commonName  ?cname.
 optional {?s  txn:thumbnail ?o.}

ORDER BY ASC(?family)

 limit 25

Run Live Query via URIburner