Sample queries: Difference between revisions

From Black Bibliography Project
Jump to navigation Jump to search
No edit summary
Line 4: Line 4:
== Instance count ==
== Instance count ==
To get an overview of what's in the BBP, the following query will return a count of all of the different instances, such as works, people, and places.
To get an overview of what's in the BBP, the following query will return a count of all of the different instances, such as works, people, and places.
<pre>
<pre>
SELECT ?typeLabel (count(distinct ?x) as ?count)
SELECT ?typeLabel (count(distinct ?x) as ?count)
Line 17: Line 16:
</pre>
</pre>
[http://tinyurl.com/vr66u8a Try it out!]
[http://tinyurl.com/vr66u8a Try it out!]
== Birthplaces ==
Map the birth places for everyone listed in the BBP, using coordinate data from Wikidata
<pre>
PREFIX wd_1: <http://www.wikidata.org/entity/>
PREFIX wdt_1: <http://www.wikidata.org/prop/direct/>
SELECT distinct ?person ?personLabel ?pob ?pobLabel ?coords
WITH {
  SELECT ?person WHERE {
    ?item wdt:P8 wd:Q3 .
    ?item wdt:P107 ?wid .
    BIND(IRI(CONCAT('http://www.wikidata.org/entity/', ?wid)) AS ?person )
  }
} AS %people
WHERE {
  include %people
  SERVICE <https://query.wikidata.org/sparql> {
    ?person wdt_1:P19 ?pob .
    ?pob wdt_1:P625 ?coords .
    ?person rdfs:label ?personLabel .
      FILTER((LANG(?personLabel)) = "en")
    ?pob rdfs:label ?pobLabel .
      FILTER((LANG(?pobLabel)) = "en")
    }
}
</pre>
[http://tinyurl.com/rgy77n5 Try it out!]
== Inscription Overview ==
<pre>
SELECT ?item ?itemLabel ?inscriptionNote ?addresseeLabel ?formerOwnerLabel WHERE {
  ?item wdt:P52 ?inscriptionNote .
  ?item ?x ?statement .
  ?statement ps:P52 ?inscriptionNote ;
            pq:P53 ?addressee .
  OPTIONAL {?statement pq:P54 ?formerOwner}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER by ?recipient
</pre>
[http://tinyurl.com/vzfh28r Try it out!]

Revision as of 20:46, 10 November 2019

Until we can update the Query Service to include our own sample queries, let's list those here...


Instance count

To get an overview of what's in the BBP, the following query will return a count of all of the different instances, such as works, people, and places.

SELECT ?typeLabel (count(distinct ?x) as ?count)
WHERE
{
  ?x wdt:P8 ?type .
  ?type rdfs:label ?typeLabel.
  FILTER((LANG(?typeLabel)) = "en")
}
group by ?type ?typeLabel
order by desc(?count)

Try it out!

Birthplaces

Map the birth places for everyone listed in the BBP, using coordinate data from Wikidata

PREFIX wd_1: <http://www.wikidata.org/entity/>
PREFIX wdt_1: <http://www.wikidata.org/prop/direct/>

SELECT distinct ?person ?personLabel ?pob ?pobLabel ?coords

WITH {
  SELECT ?person WHERE {
    ?item wdt:P8 wd:Q3 .
    ?item wdt:P107 ?wid .
    BIND(IRI(CONCAT('http://www.wikidata.org/entity/', ?wid)) AS ?person )
  }
} AS %people

WHERE {
  include %people
  SERVICE <https://query.wikidata.org/sparql> {
    ?person wdt_1:P19 ?pob .
    ?pob wdt_1:P625 ?coords .
    ?person rdfs:label ?personLabel .
      FILTER((LANG(?personLabel)) = "en")
    ?pob rdfs:label ?pobLabel .
      FILTER((LANG(?pobLabel)) = "en")
    }
}

Try it out!

Inscription Overview

SELECT ?item ?itemLabel ?inscriptionNote ?addresseeLabel ?formerOwnerLabel WHERE { 
  ?item wdt:P52 ?inscriptionNote .
  ?item ?x ?statement .
  ?statement ps:P52 ?inscriptionNote ;
             pq:P53 ?addressee .
  OPTIONAL {?statement pq:P54 ?formerOwner}
 SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER by ?recipient

Try it out!