Project:SPARQL/examples: Difference between revisions

From biodiversity citizen science
Jump to navigation Jump to search
Line 13: Line 13:
== Plot observations based on an NCBI taxon id on Wikidata ==
== Plot observations based on an NCBI taxon id on Wikidata ==
<syntaxhighlight>
<syntaxhighlight>
#Plot observations based on an NCBI taxon id on Wikidata
#Observations and their locations
#Observations and their locations
#defaultView:Map
#defaultView:Map
PREFIX wbt: <http://biodiversity.wiki.opencura.com/prop/direct/>
PREFIX wbt: <http://biodiversity.wiki.opencura.com/prop/direct/>


SELECT * WHERE {
SELECT ?observationURL ?observationIRI ?wikidata_item ?location WHERE {
   SERVICE <https://query.wikidata.org/sparql> {
   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
     ?wikidata_item p:P685/psn:P685 <http://purl.uniprot.org/taxonomy/30382> . # Get the wikidata item for the egyptian goose
     }
     }
   ?observation wbt:P8 ?location ;                                          # Get the location of an observation
   ?observationIRI wbt:P8 ?location ;                                          # Get the location of an observation
                 wbt:P9 ?scientific_name_wb .                                # Get the scientific name of the 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
   ?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)
}
}


</syntaxhighlight>
</syntaxhighlight>

Revision as of 15:07, 17 December 2019

Observations and their locations

#defaultView:Map
PREFIX wbt: <http://biodiversity.wiki.opencura.com/prop/direct/>
 
SELECT * WHERE {
   ?s wbt:P8 ?o .
}
}}

Federated queries

Plot observations based on an NCBI taxon id on Wikidata

#Plot observations based on an NCBI taxon id on Wikidata
#Observations and their locations
#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)
}