Skip to content

Instantly share code, notes, and snippets.

@baskaufs
Created May 28, 2015 18:15
Show Gist options
  • Save baskaufs/6693aaa0dbd97d6ce5a5 to your computer and use it in GitHub Desktop.
Save baskaufs/6693aaa0dbd97d6ce5a5 to your computer and use it in GitHub Desktop.
generic SPARQL query to screen images
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dwc: <http://rs.tdwg.org/dwc/terms/>
PREFIX ac: <http://rs.tdwg.org/ac/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dsw: <http://purl.org/dsw/>
PREFIX Iptc4xmpExt: <http://iptc.org/std/Iptc4xmpExt/2008-02-29/>
SELECT DISTINCT ?genus ?species ?uri
WHERE {
?organism foaf:depiction ?image.
?organism dsw:hasIdentification ?identification.
?identification dwc:genus ?genus.
?identification dwc:specificEpithet ?species.
?identification dwc:genus "Quercus".
?organism dsw:hasOccurrence ?occ.
?occ dsw:atEvent ?event.
?event dsw:locatedAt ?loc.
?loc dwc:stateProvince "California".
?image ac:hasServiceAccessPoint ?SAP.
?SAP ac:variant ac:LowerQuality.
?SAP ac:accessURI ?uri.
?image Iptc4xmpExt:CVterm ?view.
?view rdfs:subClassOf ?category.
?category rdfs:label "fruit".
}
LIMIT 50
@baskaufs
Copy link
Author

Explanation of the query:
Lines 1-6: define the namespace abbreviations used in the query. In Callimachus, these can be omitted once a query has been run using those abbreviations.

Line 8: ?genus and ?species is included so that the output will show the scientific name of the depicted organisms. ?uri is the URL that can be used to retrieve the raw image via HTTP (vs. retrieving a web page about the image).

Line 10: specifies that the organism is depicted by an image.

Lines 12-15: requires that the organism be identified to the genus "Quercus" (i.e. oaks). Any other genus could be specified by changing the literal value in line 15, e.g. "Astragalus" (ground plums), "Acer" (maples), "Asclepias" (milkweeds), etc.

Lines 17-20: require that the organism occur in the state of California. Any other state or province could be substituted, e.g. "Arkansas", "Tennessee", "Ohio".

Lines 22-24: specify that the raw image (service access point) be of a size suitable for web pages (ac:LowerQuality). Other possible sizes include: ac:GoodQuality (large images), ac:Thumbnail (thumbs).

Lines 26-28: specify the general category of view for the image, restricting it to images of fruits. Other possible categories are "inflorescence", "cone", "bark", "whole plant", "whole tree".

Of course it is possible that there will be no URLs returned for a query if the combination of options chosen create triple patterns that are not satisfied by any ?uri .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment