Wikidata:SPARQL query service/queries/examples/bibliographic

Showcase Queries

edit

These queries showcase queries for retrieving bibliographical information using SPARQL.

Biographical articles published in the Alumni Oxonienses, 1st edition

edit
# List articles in the Alumni Oxonienses, 1st ed.
SELECT ?item ?itemLabel ?page ?volume ?subject ?subjectLabel
WHERE
{
  VALUES (?BIOGRAPHICAL_ARTICLE ?ALUM_OX_1ST) { (
    wd:Q19389637
    wd:Q19036877
  ) }
  ?item wdt:P31 ?BIOGRAPHICAL_ARTICLE; # is a biographical article (Q19389637)
    p:P1433 ?published_in_statement.
  ?published_in_statement ps:P1433 ?ALUM_OX_1ST. # published in Alumni Oxonienses, 1st ed.
  ?published_in_statement a wikibase:BestRank.
  OPTIONAL { ?published_in_statement pq:P304 ?page. }
  #?published_in_statement pq:P304 "77".  # change the above line to this line to restrict to page 77.
  OPTIONAL { ?published_in_statement pq:P478 ?volume. }
  OPTIONAL { ?item wdt:P921 ?subject. }
  # FILTER (xsd:integer(?page) >= 50 && xsd:integer(?page) <= 100) # add this line to restrict to pages in the range 50–100.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!

Encyclopedic articles with certain subjects

edit
# Encyclopedic articles with certain subjects
select ?article ?articleTitle ?parentWork ?parentWorkLabel 
{
  VALUES ?ENCYC_ARTICLE { wd:Q13433827 }
  VALUES ?ARTICLE_SUBJECT {wd:Q142 wd:Q31} # France or Belgium
  
  # articles with the given subject
  ?article wdt:P31/wdt:P279* ?ENCYC_ARTICLE;
           wdt:P921 ?ARTICLE_SUBJECT .
  hint:Prior hint:runFirst true.
  
  OPTIONAL { ?article wdt:P1476 ?articleTitle }
  OPTIONAL { ?article wdt:P1433 ?parentWork }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # used to display a label
}
Try it!

Items described within a book, with optional page number from qualifier

edit
SELECT ?item ?itemLabel ?page_number
WHERE
{
   ?item p:P1343 ?described_by .  # described by source (P1343)
   ?described_by ps:P1343 wd:Q28927781 . # Great Women Masters of Art (Q28927781)
   OPTIONAL { ?described_by pq:P304 ?page_number } # page number (P304)
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY xsd:integer(?page_number)
Try it!

Abbreviations used by the National Union Catalog

edit
# Abbreviations used by the National Union Catalog
SELECT ?item ?itemLabel ?abbreviation WHERE {
  VALUES ?NUC {wd:Q3336951 } # National Union Catalog
  # abbreviation qualified by used by: NUC
  ?item p:P8703 [ pq:P1535 ?NUC ];
    # and get the abbreviation itself
    wdt:P8703 ?abbreviation.

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!

Volumes of a periodical published between certain dates

edit
# Volumes of a periodical with a publication date set
SELECT ?item ?itemLabel ?pubdate ?parentLabel WHERE {
  VALUES (?fromDate ?toDate) {
    (
      "1800-01-01"^^xsd:dateTime
      "1901-01-01"^^xsd:dateTime
    )
  }
  
  # anything that's a volume that's part of a periodical
  ?item (wdt:P31/(wdt:P279*)) wd:Q1238720;
      wdt:P179 ?parent.
  ?parent (wdt:P31/(wdt:P279*)) wd:Q1002697.
 
  ?item wdt:P577 ?pubdate. # get the publication date
  # filter to the period of interest
  FILTER((?pubdate > ?fromDate) && (?pubdate < ?toDate))
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!

ISIL Codes of institutions in the US and UK

edit
# Get the ISIL identifier of libraries in the US and UK
SELECT ?item ?itemLabel ?isil 
WHERE 
{
  VALUES ?COUNTRIES { wd:Q30 wd:Q145 }
  ?item wdt:P791 ?isil;
        wdt:P17 ?COUNTRIES
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!