Project:SPARQL/examples: Difference between revisions
Jump to navigation
Jump to search
(example) |
|||
Line 20: | Line 20: | ||
GROUP BY ?scientific_nameURL ?scientific_nameIRILabel | GROUP BY ?scientific_nameURL ?scientific_nameIRILabel | ||
ORDER BY DESC(?counts) | ORDER BY DESC(?counts) | ||
</syntaxhighlight> | |||
== Observations of selected bird species as map layers == | |||
<syntaxhighlight> | |||
# Observations of frequent bird species and their geoocoordinates | |||
# Species: | |||
# - Anas platyrhynchos (Q367) | |||
# - Larus occidentalis (Q37) | |||
# - Branta canadensis (Q345) | |||
# - Turdus migratorius (Q107) | |||
# - Zenaida macroura (Q257) | |||
#defaultView:Map | |||
PREFIX wbt: <http://biodiversity.wiki.opencura.com/prop/direct/> | |||
PREFIX wb: <http://biodiversity.wiki.opencura.com/entity/> | |||
SELECT DISTINCT ?s ?o ?layer WHERE { | |||
?s wbt:P8 ?o . | |||
?s wbt:P9 ?t. | |||
FILTER(?t IN (wb:Q367, wb:Q37, wb:Q345, wb:Q107, wb:Q257)). | |||
BIND(?t AS ?layer). | |||
} | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 18:55, 3 January 2020
Observations and their locations
#defaultView:Map
PREFIX wbt: <http://biodiversity.wiki.opencura.com/prop/direct/>
SELECT * WHERE {
?s wbt:P8 ?o .
}
Species covered and counts
PREFIX wbt: <http://biodiversity.wiki.opencura.com/prop/direct/>
SELECT ?scientific_nameURL ?scientific_nameIRILabel (COUNT(?scientific_nameIRI) AS ?counts) WHERE {
?observationIRI wbt:P9 ?scientific_nameIRI .
BIND (iri(replace(str(?scientific_nameIRI), "entity/", "wiki/Item:")) as ?scientific_nameURL)
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?scientific_nameURL ?scientific_nameIRILabel
ORDER BY DESC(?counts)
Observations of selected bird species as map layers
# Observations of frequent bird species and their geoocoordinates
# Species:
# - Anas platyrhynchos (Q367)
# - Larus occidentalis (Q37)
# - Branta canadensis (Q345)
# - Turdus migratorius (Q107)
# - Zenaida macroura (Q257)
#defaultView:Map
PREFIX wbt: <http://biodiversity.wiki.opencura.com/prop/direct/>
PREFIX wb: <http://biodiversity.wiki.opencura.com/entity/>
SELECT DISTINCT ?s ?o ?layer WHERE {
?s wbt:P8 ?o .
?s wbt:P9 ?t.
FILTER(?t IN (wb:Q367, wb:Q37, wb:Q345, wb:Q107, wb:Q257)).
BIND(?t AS ?layer).
}
Federated queries
Plot observations based on an NCBI taxon id on Wikidata
#defaultView:Map
PREFIX wbt: <http://biodiversity.wiki.opencura.com/prop/direct/>
SELECT ?observationURL ?observationIRI ?wikidata_item ?location WHERE {
SERVICE <https://query.wikidata.org/sparql> {
?wikidata_item p:P685/psn:P685 <http://purl.uniprot.org/taxonomy/30382> . # Get the wikidata item for the egyptian goose
}
?observationIRI wbt:P8 ?location ; # Get the location of an observation
wbt:P9 ?scientific_name_wb . # Get the scientific name of the observation
?scientific_name_wb wbt:P11 ?wikidata_item . # get the mapping from Wikidata for the scientific name
BIND (iri(replace(str(?observationIRI), "entity/", "wiki/Item:")) as ?observationURL)
}