4

I'm trying to have a list of Italian books from the 1980 on and the number of Wikipedia pages their original Wikipedia page has been translated into, for instance I would like to have:

Book, number
The name of the Rose, 5

Where 5 is the number of languages The Name of the Rose has been translated into in Wikipedia, for instance there is an English wiki page, a Dutch one, a Spanish one, a French one, a Greek one.

Here is the query so far:

SELECT ?item ?label 
WHERE
{
  VALUES ?type {wd:Q571 wd:Q7725634}  # book or literary work
  ?item wdt:P31 ?type .
  ?item wdt:P577 ?date FILTER (?date > "1980-01-01T00:00:00Z"^^xsd:dateTime) . #dal 1980
  ?item rdfs:label ?label filter (lang(?label) = "it")
  ?item wdt:P495 wd:Q38 .


}

I get the list of books, but I can't find the right property to look for.

  • `SELECT ?item ?label (count(?lang) as ?numWikipediaLanguages) WHERE { hint:Query hint:optimizer "None". VALUES ?type {wd:Q571 wd:Q7725634} # book or literary work ?item wdt:P31 ?type . ?item wdt:P577 ?date . hint:Prior hint:rangeSafe "true" . FILTER (?date > "1980-01-01T00:00:00Z"^^xsd:dateTime) . #dal 1980 ?item rdfs:label ?label filter (lang(?label) = "it") ?item wdt:P495 wd:Q38 . ?article schema:about ?item ; schema:inLanguage ?lang ; schema:isPartOf [ wikibase:wikiGroup "wikipedia" ] . } group by ?item ?label` – UninformedUser Aug 26 '21 at 17:03
  • Thank you so much! I was wondering, I get only about 400 items but they must be more... – Semantic_researcher Aug 26 '21 at 18:39
  • which ones would you say are missing for examples? I mean in the end it depends on the data in Wikidata – UninformedUser Aug 29 '21 at 03:16

1 Answers1

2

Did you actually get The Name of the Rose in your example? Because its date of publication is set to 1980 (which is = 1980-01-01 for our purposes), I had to change your query to a >= comparison.

Then, using COUNT() and GROUP BY as mentioned in the comment gets you what you want. But if you really just need the number of sitselinks, there is a shortcut that may be useful. It was added because that number is often used as a good proxy for an item's popularity, and using the precomputed number is vastly more efficient than getting all links, grouping, and counting.

SELECT ?book ?bookLabel ?sitelinks ?date WHERE {
  VALUES ?type { wd:Q571 wd:Q47461344 wd:Q7725634 }
  ?book wdt:P31 ?type;
        wdt:P577 ?date;
        wdt:P495 wd:Q38;
        wikibase:sitelinks ?sitelinks.
  FILTER((?date >= "1980-01-01T00:00:00Z"^^xsd:dateTime) && (?date < "1981-01-01T00:00:00Z"^^xsd:dateTime))
  SERVICE wikibase:label { bd:serviceParam wikibase:language "it,en". }
}

Query

Note that the values may slightly differ from the version with group & count because here sites such as commons or wikiquote are also included.

Matthias Winkelmann
  • 15,870
  • 7
  • 64
  • 76