Project:SPARQL/examples: Difference between revisions

 
(15 intermediate revisions by the same user not shown)
Line 1: Line 1:
= Requests and Suggestions =
= Examples =
== Observations and their locations ==
== Observations and their locations ==
<sparql tryit="1" listing="1">
<sparql tryit="1" list="1">
#defaultView:Map
#defaultView:Map
PREFIX wbt: <http://biodiversity.wiki.opencura.com/prop/direct/>
PREFIX wbt: <http://biodiversity.wikibase.cloud/prop/direct/>
   
   
SELECT * WHERE {
SELECT * WHERE {
Line 10: Line 13:


== Species covered and counts ==
== Species covered and counts ==
<sparql tryit="1" listing="1">
<sparql tryit="1" list="1">
PREFIX wbt: <http://biodiversity.wiki.opencura.com/prop/direct/>
PREFIX wbt: <http://biodiversity.wiki.opencura.com/prop/direct/>


Line 23: Line 26:


== Observations of selected bird species as map layers ==
== Observations of selected bird species as map layers ==
<syntaxhighlight>
<sparql tryit="1" list="1">
# Observations of frequent bird species and their geoocoordinates
# Observations of frequent bird species and their geoocoordinates
# Species:
# Species:
Line 40: Line 43:
BIND(?t AS ?layer).
BIND(?t AS ?layer).
}
}
</syntaxhighlight>
</sparql>


= Federated queries =
= Federated queries =


== Egg-incubation time of the bird observed with iNaturalist ==
== Egg-incubation time of the bird observed with iNaturalist ==
<syntaxhighlight>
<sparql tryit="1" list="1">
PREFIX wb: <http://biodiversity.wiki.opencura.com/entity/>
PREFIX wb: <http://biodiversity.wiki.opencura.com/entity/>
PREFIX wbt: <http://biodiversity.wiki.opencura.com/prop/direct/>
PREFIX wbt: <http://biodiversity.wiki.opencura.com/prop/direct/>
Line 59: Line 62:
     }
     }
}
}
</syntaxhighlight>
</sparql>


== Plot observations based on an NCBI taxon id on Wikidata ==
== Plot observations based on an NCBI taxon id on Wikidata ==
<syntaxhighlight>
<sparql tryit="1" list="1">
#defaultView:Map
#defaultView:Map
PREFIX wbt: <http://biodiversity.wiki.opencura.com/prop/direct/>
PREFIX wbt: <http://biodiversity.wiki.opencura.com/prop/direct/>
Line 76: Line 79:
}
}


</syntaxhighlight>
</sparql>
 
== iNaturalist observations without a Wikipedia article (in any language) ==
<sparql tryit="1" list="1">
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". }
  }
</sparql>
 
== species observed through iNaturalist not being described by an English Wikipedia article ==
<sparql tryit="1" list="1">
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". }
  }
</sparql>
 
== species observed through iNaturalist in New Zealand not being described by an English Wikipedia article ==
<sparql tryit="1" list="1">
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". }
}
</sparql>
 
== Observations by a select set of observers that are not being described on the English Wikipedia ==
<sparql tryit="1" list="1">
#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". }
}
</sparql>
Bots, Bureaucrats, emailconfirmed, Administrators
603,740

edits