Wikidata:WikiProject Books/Queries

From Wikidata
Jump to navigation Jump to search

See Wikidata:Request a query too.

Books from an author with their publication date[edit]

Example here with Gilles Deleuze (Q184226)

SELECT ?book ?bookLabel ?date WHERE {
  ?book wdt:P31/wdt:P279* wd:Q571 .
  ?book wdt:P50 wd:Q184226 .
  OPTIONAL {
    ?book wdt:P577 ?date .
  }
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en,fr"
  }
}
Try it!

Items that are about a U.S. supreme court decision and have a Wikisource (en.wikisource) page[edit]

SELECT ?item ?itemLabel ?article
WHERE
{
    ?item wdt:P31 wd:Q19692072 .
    ?article schema:about ?item ;
    schema:isPartOf    <https://en.wikisource.org/> .
    SERVICE wikibase:label {
      bd:serviceParam wikibase:language "en"
    }
}
Try it!

Wikidata Graph Builder (starting on Roe v. Wade (Q300950)) : here

Books on french wikisource by person born in Quebec[edit]

#books on french wikisource by person born in Quebec
SELECT ?livre ?livreLabel ?lieuLabel ?page WHERE {
	?livre wdt:P50 ?personne.
	?personne wdt:P19 ?lieu.
	?lieu wdt:P131+ wd:Q176.
	?page schema:about ?livre.
	?page schema:isPartOf <https://fr.wikisource.org/> .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". }
}
Try it!

Books on any wikisource by person born in Lombardy[edit]

#books on any wikisource by person born in Lombardy
SELECT DISTINCT ?book ?page WHERE {
    ?book wdt:P50 ?person.
    ?person wdt:P19 ?place.
    ?place wdt:P131+ wd:Q1210. 
    ?page schema:about ?book .
    ?page schema:isPartOf/wikibase:wikiGroup "wikisource" 	
} limit 10
Try it!

(limit to the 10 first to avoid times out - maybe query can be improved?)

Plays by Jean Racine Q742 by number of characters[edit]

NEED IMPROVEMENTS/CLEANING
#Plays by Jean Racine Q742 by number of characters
SELECT ?play (COUNT(DISTINCT ?character) AS ?nbChar) WHERE {
  ?play wdt:P50 wd:Q742.
  ?play wdt:P674 ?character.
}
GROUP BY ?play
Try it!

Authors on the Italian Wikisource[edit]

#Authors on the Italian Wikisource
SELECT ?author ?authorLabel
WHERE
{
	?author wdt:P31 wd:Q5 . #who are human
    ?page schema:about ?author.
	?page schema:isPartOf <https://it.wikisource.org/> . #who are on it.wikisource.org
	SERVICE wikibase:label { bd:serviceParam wikibase:language "it" }
}
Try it!

Narrative locations in travel books on a map (and by layer)[edit]

#defaultView:Map
SELECT ?book ?bookLabel ?place ?placeLabel ?coord ?layer WHERE {
  ?book wdt:P840 ?place ; wdt:P136 wd:Q1164267 . #books with "narrative location" and which are "travel books"
  ?place wdt:P625 ?coord . #take coordinates from the location

  ?book rdfs:label ?layer . #take the name for the legend of the layer
  FILTER(LANG(?layer) = "fr") . #take only the name in French
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr" . }
}
Try it!

Book with « Bretagne » in the French label[edit]

#Book French with « Bretagne » in the French label
SELECT distinct ?book ?title ?authorLabel
WHERE
{
	?book rdfs:label ?title ;wdt:P31 wd:Q3331189 ;
	FILTER (lang(?title) = "fr"). 
	FILTER regex (?title, "Bretagne").
	SERVICE wikibase:label { bd:serviceParam wikibase:language "fr" }
}
Try it!

Templates on Wikisources[edit]

Templates used on Wikisources (sorted by numbers of Wikisources where it is used), could be useful to spread good templates.

SELECT DISTINCT ?template ?templateLabel (COUNT(DISTINCT ?page) as ?count) (GROUP_CONCAT(DISTINCT(?page); separator=", ") as ?pages) WHERE {
    ?template wdt:P31/wdt:P279* wd:Q11266439 .
    ?page schema:about ?template .
    ?page schema:isPartOf/wikibase:wikiGroup "wikisource"
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?template ?templateLabel
ORDER BY DESC(?count)
limit 10
Try it!