Sample queries: Difference between revisions

From Black Bibliography Project
Jump to navigation Jump to search
No edit summary
Line 14: Line 14:
</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 ?from ?to
WHERE {
  ?item wdt:P52 ?inscriptionNote .
  ?item rdfs:label ?itemLabel .
  ?item ?x ?statement .
  ?statement ps:P52 ?inscriptionNote ; pq:P53 ?addressee ; pq:P54 ?inscriber .
  ?addressee rdfs:label ?to .
  ?inscriber rdfs:label ?from .
}
ORDER by ?from
</pre>
[http://tinyurl.com/vd7dhfm Try it out!]


== First 100 Works ==
== First 100 Works ==
Line 59: Line 106:
</pre>
</pre>
[http://tinyurl.com/utregjf Try it out!]
[http://tinyurl.com/utregjf 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 ?from ?to
WHERE {
  ?item wdt:P52 ?inscriptionNote .
  ?item rdfs:label ?itemLabel .
  ?item ?x ?statement .
  ?statement ps:P52 ?inscriptionNote ; pq:P53 ?addressee ; pq:P54 ?inscriber .
  ?addressee rdfs:label ?to .
  ?inscriber rdfs:label ?from .
}
ORDER by ?from
</pre>
[http://tinyurl.com/vd7dhfm Try it out!]

Revision as of 02:24, 11 November 2019

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 ?from ?to 
WHERE { 
  ?item wdt:P52 ?inscriptionNote .
  ?item rdfs:label ?itemLabel .
  ?item ?x ?statement .
  ?statement ps:P52 ?inscriptionNote ; pq:P53 ?addressee ; pq:P54 ?inscriber .
  ?addressee rdfs:label ?to .
  ?inscriber rdfs:label ?from .
}
ORDER by ?from

Try it out!


First 100 Works

Get a list of all of the works
(as of 2019-11, that's exactly 100 works!)

SELECT ?work ?workLabel (count(distinct ?edition) as ?editions) 
(min(?year) as ?earliestPublicationDate)
(GROUP_CONCAT(distinct ?authorLabel; SEPARATOR="; ") as ?authors)
(GROUP_CONCAT(distinct ?literaryFormLabel; SEPARATOR="; ") as ?format)
WHERE
{
  ?work wdt:P8 wd:Q4 .
  OPTIONAL { ?work wdt:P90 ?author . ?author rdfs:label ?authorLabel }
  OPTIONAL { ?work wdt:P11 ?literaryForm . ?literaryForm rdfs:label ?literaryFormLabel }
  OPTIONAL { ?edition wdt:P13 ?work . ?edition p:P29|p:P32 ?pubStatement } 
  OPTIONAL { ?pubStatement pq:P31 ?date . 
            BIND(str(YEAR(?date)) AS ?year) }
  ?work rdfs:label ?workLabel .
}
group by ?work ?workLabel
order by ?workLabel

Author Gallery

Return a list of everyone in the BBP listed as an author, as long as they also have a picture in Wikimedia commons, and sort the results by the total number of works listed.

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

SELECT distinct ?person ?personLabel ?pic (COUNT(distinct ?work) as ?workCount)
WHERE
{
    ?person wdt:P8 wd:Q3 .
    ?person rdfs:label ?personLabel .
    ?person wdt:P107 ?wid .
    ?person ^wdt:P90 ?work .
    BIND(IRI(CONCAT('http://www.wikidata.org/entity/', ?wid)) AS ?wikidataURI )
    SERVICE <https://query.wikidata.org/sparql> {
    ?wikidataURI wdt_1:P18 ?pic .
    }
}
group by ?person ?personLabel ?pic
order by desc(?workCount)

Try it out!