Project:SPARQL/examples
Jump to navigation
Jump to search
Requests and Suggestions
Examples
Observations and their locations
The following query uses these:
#defaultView:Map
PREFIX wbt: <http://biodiversity.wikibase.cloud/prop/direct/>
SELECT * WHERE {
?s wbt:P8 ?o .
}
Species covered and counts
The following query uses these:
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
The following query uses these:
# 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
Egg-incubation time of the bird observed with iNaturalist
The following query uses these:
PREFIX wb: <http://biodiversity.wiki.opencura.com/entity/>
PREFIX wbt: <http://biodiversity.wiki.opencura.com/prop/direct/>
SELECT * WHERE {
VALUES ?observation {wb:Q46561}
?observation wbt:P8 ?coordinate_location ;
wbt:P1 ?observation_id ;
wbt:P9 ?scientific_name .
?scientific_name wbt:P11 ?wikidata_iri .
SERVICE <https://query.wikidata.org/sparql> {
?wikidata_iri wdt:P7770 ?egg_incubation_time .
}
}
Plot observations based on an NCBI taxon id on Wikidata
The following query uses these:
#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)
}
iNaturalist observations without a Wikipedia article (in any language)
The following query uses these:
PREFIX wbt: <http://biodiversity.wiki.opencura.com/prop/direct/>
PREFIX wb: <http://biodiversity.wiki.opencura.com/entity/>
SELECT ?taxon ?taxonLabel ?wikidata WHERE {
?taxon wbt:P13 wb:Q131918 ;
wbt:P11 ?wikidata .
SERVICE <https://query.wikidata.org/sparql> {
?wikidata wdt:P31 ?type .
FILTER NOT EXISTS {?article schema:about ?wikidata .}
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
species observed through iNaturalist not being described by an English Wikipedia article
The following query uses these:
PREFIX wbt: <http://biodiversity.wiki.opencura.com/prop/direct/>
PREFIX wb: <http://biodiversity.wiki.opencura.com/entity/>
SELECT DISTINCT ?taxon ?taxonLabel ?wikidata WHERE {
?taxon wbt:P13 wb:Q131918 ;
wbt:P11 ?wikidata .
SERVICE <https://query.wikidata.org/sparql> {
?wikidata wdt:P31 [] .
MINUS {?article schema:about ?wikidata ;schema:isPartOf <https://en.wikipedia.org/> ;schema:inLanguage "en" .}
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
species observed through iNaturalist in New Zealand not being described by an English Wikipedia article
The following query uses these:
PREFIX wbt: <http://biodiversity.wiki.opencura.com/prop/direct/>
PREFIX wb: <http://biodiversity.wiki.opencura.com/entity/>
SELECT DISTINCT ?country ?taxon ?taxonLabel ?wikidata WITH {
SELECT * WHERE {
VALUES ?country {wd:Q664} # new zealand
SERVICE wikibase:around {
?observation wbt:P8 ?location .
bd:serviceParam wikibase:center ?loc .
bd:serviceParam wikibase:radius "100" .
}
SERVICE <https://query.wikidata.org/sparql> {
?country wdt:P625 ?loc .
}
}
} as %result
WHERE {
INCLUDE %result
?observation wbt:P9 ?taxon .
?taxon wbt:P11 ?wikidata .
SERVICE <https://query.wikidata.org/sparql> {
?wikidata wdt:P31 [] .
MINUS {?article schema:about ?wikidata ;schema:isPartOf <https://en.wikipedia.org/> ;schema:inLanguage "en" .}
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Observations by a select set of observers that are not being described on the English Wikipedia
The following query uses these:
#species observed through iNaturalist in New Zealand not being described by an English Wikipedia article
PREFIX wbt: <http://biodiversity.wiki.opencura.com/prop/direct/>
PREFIX wb: <http://biodiversity.wiki.opencura.com/entity/>
PREFIX observer: <https://www.inaturalist.org/people/>
SELECT DISTINCT
?observer
?taxon
?taxonLabel
?wikidata
?observationUrl
?observationPhoto
WHERE {
VALUES ?observer {
observer:andrawaag
}
?observation wbt:P9 ?taxon ;
wbt:P6 ?observationUrl ;
wbt:P7 ?observationPhoto ;
wbt:P3 ?observer .
?taxon wbt:P11 ?wikidata .
SERVICE <https://query.wikidata.org/sparql> {
?wikidata wdt:P31 [] .
MINUS {?article schema:about ?wikidata ;schema:isPartOf <https://en.wikipedia.org/> ;schema:inLanguage "en" .}
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}