## page was renamed from Datasets/WikidataExplanation = Wikidata: various explanations = A good SPARQL tutorial specifically for Wikidata and its particular schema can be found here: https://www.wikidata.org/wiki/Wikidata:SPARQL_tutorial <> == Sitelinks == A sitelink is a Wikipedia page that is about a certain Wikidata entity. The number of sitelinks is a good proxy for the popularity of an entity. For example, to get all German cities and their population ordered by the number of sitelinks, one can write the following. If you [[https://goo.gl/QhjjuL|run the query on WDQS]], note how in the top results there is strong correlation to population size. {{{ SELECT ?label ?population (COUNT(?label) AS ?popularity) WHERE { ?city wdt:P31 wd:Q515 . # ?city "instance of" "city" ?city wdt:P17 wd:Q183 . # ?city "country" "Germany" ?city wdt:P1082 ?population . # ?city "population" ?population ?city rdfs:label ?label . ?sitelink schema:about ?city FILTER(LANG(?label) = "en") } GROUP BY ?label ?population ORDER BY DESC(?popularity) LIMIT 100 }}} == Obtaining names for entities and predicates == The [[https://query.wikidata.org|Wikidata Query Service (WDQS)]] has an automatic mechanism for obtaining the single best name for entity variables in the query. It does not work for predicate names, however. The mechanism is invoked by adding this line to the SPARQL query: {{{ SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } }}} To obtain a single name of an entity "manually" (= without the mechanism above), one can add the following two lines to a query ([[https://www.wikidata.org/wiki/Q90|Q90]] is Paris). Note that without the language filter, one gets one name for each languages, for which a name has been specified for that entity in Wikidata (for popular entities, these are usually very many): {{{ wd:Q90 rdfs:label ?label . FILTER(LANG(?label) = "en") }}} Obtaining the name for a predicate is a bit more complicated. Here is how to obtain all predicates and their English name for an entity (again Q90), sorted by the number of triples with that predicate and that entity as subject: {{{ SELECT ?p (COUNT(?o) as ?count) WHERE { wd:Q90 ?p ?o . ?x wikibase:claim ?p . ?x rdfs:label ?label . FILTER(LANG(?label) = "en") } GROUP BY ?p ORDER BY DESC(?count) LIMIT 100 }}} There are a number of other wikibase: predicates that relate the different types of predicates to teach other {{{ wd:P47 wikibase:claim p:P47 wd:P47 wikibase:directClaim wdt:P47 wd:P47 wikibase:novalue wdno:P47 wd:P47 wikibase:qualifier pq:P47 wd:P47 wikibase:qualifierValue pqv:P47 wd:P47 wikibase:reference pr:P47 wd:P47 wikibase:referenceValue prv:P47 wd:P47 wikibase:statementProperty ps:P47 wd:P47 wikibase:statementValue psv:P47 }}}