Hot answers tagged

32 votes

Get Wikipedia URLs (sitelinks) in Wikidata SPARQL query

On 18. April 2016 the ticket "More efficient SPARQL queries for sitelinks" brought us a better way: schema:isPartOf. ?sitelink schema:about ?item . ?sitelink schema:inLanguage "en" . ?sitelink ...
robbi5's user avatar
  • 421
15 votes
Accepted

Querying Wikidata : WDQ vs. WDQS / SPARQL

I'm the developer of WDQ. It was developed as a stop-gap measure, until Wikidata would get its own query service. That took some years, but now we have SPARQL and https://query.wikidata.org/ so I plan ...
Magnus Manske's user avatar
15 votes
Accepted

How to include sub-classes in a Wikidata SPARQL query? (example: when querying "bands", include "rock bands")

The right expression to use here is p:P31/ps:P31/wdt:P279*. Explanation: p:P31/ps:P31 means instance of, or instance of not marked as preferred. Only using p:P31 at this step would miss some ...
Nicolas Raoul's user avatar
  • 8,416
7 votes
Accepted

Wikidata get property of property

The point in time property of the award received is what Wikidata calls a qualifier: Along with sources and ranks, qualifiers allow statements to be expanded on, annotated, or contextualized beyond ...
Patrick Hoefler's user avatar
6 votes
Accepted

Get QID from Wikidata label name, via SPARQL

Yes, you can, but it isn't short: SELECT distinct ?item ?itemLabel ?itemDescription WHERE{ ?item ?label "Mozambique"@en. ?item wdt:P31 wd:Q6256 . ?article schema:about ?item . ?article ...
Alexan's user avatar
  • 442
6 votes

Retrieve periodic table information from wikidata

I think this is close to what you want but there doesn't seem to be a property for group or period as a number. SELECT ?element ?elementLabel ?symbol ?protons ?group ?groupLabel ?period ?periodLabel ...
chrisis's user avatar
  • 388
5 votes
Accepted

Wikidata SPARQL, why an intermediate item is needed in this sample query?

In the original query ?property and ?p are distinct values: ?property is wd:P54 (short for <http://www.wikidata.org/entity/P54>) and ?p is wdt:P54 (short for <http://www.wikidata.org/prop/...
svick's user avatar
  • 859
5 votes

Querying Wikidata : WDQ vs. WDQS / SPARQL

As Magnus Manske points out, SPARQL is the preferred way since, I would add, SPARQL is standardized BUT, here is the downside: The SPARQL endpoint, at this point in time, is NOT as reliable as WDQ ...
David Sánchez Martín's user avatar
5 votes

Querying Wikidata : WDQ vs. WDQS / SPARQL

You can abbreviate SPARQL by expanding a given query fragment with default namespace definitions and other options. For instance the wikidata query command line client expands wdq -tplanet '?planet ...
Jakob's user avatar
  • 195
5 votes
Accepted

How to output the description of Wikidata items using SPARQL?

I am far from expert in this, but your question motivated me to learn a little, and I have a solution, below. In short, there is a "label service" which can be added to the WHERE clause. By simply ...
Joe Germuska's user avatar
  • 5,488
4 votes

How to output the description of Wikidata items using SPARQL?

Include SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } inside your WHERE clause Append the magic string Label and Description to the variable names of your SELECT For instance, if ...
Nicolas Raoul's user avatar
  • 8,416
4 votes
Accepted

Retrieve periodic table information from wikidata

Using the series ordinal added to the chemical groups, I can extract the group and period numbers with this query. SELECT ?element ?symbol ?protons ?group ?groupNumber ?period ?periodNumber WHERE { ...
Ben's user avatar
  • 201
4 votes
Accepted

get item's properties know QID

I asked similar question on SO and got 2 answers. first answer: Using the URI instead of the variable ?item will get the information based on the entity Albert Einstein: PREFIX schema: <...
Alexan's user avatar
  • 442
4 votes
Accepted

Search in wikidata with specific Q code

In short, URIs are "things, not strings". The filtering condition should be: ?item = <http://www.wikidata.org/entity/Q6015113>, or ?item = wd:Q6015113, or ?item = URI("http://www.wikidata.org/...
Stanislav Kralin's user avatar
4 votes
Accepted

Weird results in search from wikidata

...like if I made the filter of my 50 previous results... Wikibase:mwapi supports the limit parameter of the Entity Search service: SELECT ?item ?label ?order WHERE { VALUES (?type ?name) {(wd:Q5 "...
Stanislav Kralin's user avatar
4 votes
Accepted

Why does Wikidata's query interface return no results for entities with an id of Q10000001 or higher?

There isn't an article about Татьяна Колотильщикова in English Wikipedia. Just comment out the second and the third triple patterns in your query. Or try e. g. Q11000001 instead of Q10000001.
Stanislav Kralin's user avatar
4 votes
Accepted

Limiting a SPARQL Query to Lastest Point in Time

SELECT ?itemLabel ?population ?date { ?item wdt:P31 wd:Q50337; p:P1082 [pq:P585 ?date; ps:P1082 ?population] FILTER NOT EXISTS {?item p:P1082 [pq:P585 ?date_] FILTER (?date_ > ?date)} ...
Stanislav Kralin's user avatar
4 votes
Accepted

Does Wikidata offer inferencing/reasoning?

You can test that by inspecting the results of executing a query that assumes reasoning. For example, subclass of in RDFS is a transitive property. Therefore, querying for subclass of author, should ...
pgmank's user avatar
  • 161
3 votes

Find all Wikidata items that use a particular P18 picture

As pointed out by Stanislav Kralin, here is the correct query: SELECT ?item WHERE { ?item wdt:P18 <http://commons.wikimedia.org/wiki/Special:FilePath/Gthumb.svg>. }
Nicolas Raoul's user avatar
  • 8,416
3 votes
Accepted

Most efficient way to get the Wikidata entity for a city, given as a string

SELECT ?location ?locationLabel WHERE { ?location wdt:P17 wd:Q39. ?location wdt:P31 ?settlement . ?settlement wdt:P279 wd:Q486972 . ?location rdfs:label ?de_label . FILTER (lang(?de_label) = ...
Stanislav Kralin's user avatar
3 votes
Accepted

Sort results by proximity with the "around" service in Wikidata

SELECT ?place ?placeLabel ?location ?distance WHERE { wd:Q64 wdt:P625 ?arcLoc . ?place wdt:P31 wd:Q515 . ?place wdt:P17 wd:Q183 . SERVICE wikibase:around { ?...
Stanislav Kralin's user avatar
3 votes

Wikidata get property of property

You're trying to access qualifiers, that is statements on statements, all the doc you need is here: https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries#Working_with_qualifiers
maxlath's user avatar
  • 266
3 votes
Accepted

get label (Name) instead QID field

Just add ?directorLabel to the select. The label service seems to work on any declared variable if you suffix it with 'Label'
chrisis's user avatar
  • 388
3 votes

How to get all Wikidata items in a country?

Not as straight forward as it seems. Here's a first attempt which works for the Liberian example. SELECT ?item ?territory ?territoryLabel WHERE { ?item wdt:P31 wd:Q3917681. # instance of: ...
chrisis's user avatar
  • 388
3 votes
Accepted

Wikidata SPARQL with optional qualifiers

SELECT ?painting ?paintingLabel ?material ?materialLabel ?appliesTo ?appliesToLabel { VALUES (?painting) {(wd:Q12418)} ?painting p:P186 ?statement . ?statement ps:P186 ?material OPTIONAL { ?...
Stanislav Kralin's user avatar
3 votes

Where can I find databases in .rdf or in .ttl format

Information Retrieval Dataset - Internet Movie Database (IMDB) Description This dataset was constructed for an Information Retrieval research project to obtain a master's degree at the Federal ...
Orophile's user avatar
  • 1,731
2 votes

How to include sub-classes in a Wikidata SPARQL query? (example: when querying "bands", include "rock bands")

Something like SELECT ?item ?type ?typeLabel WHERE { ?type (a | wdt:P279) wd:Q12280. # Item's type is subclass of bridge ?item wdt:P31 ?type. SERVICE wikibase:label { bd:...
chrisis's user avatar
  • 388
2 votes
Accepted

Can SPARQL modify data like SQL? Or is it read-only?

There is SPARQL Update. It doesn't seem to be supported by Wikidata Query Service.
svick's user avatar
  • 859
2 votes

GIThub to share a set of SPARQL queries

You should check out grlc grlc, the git repository linked data API constructor, automatically builds Web APIs using SPARQL queries stored in git repositories. Basically you use an github ...
jonas's user avatar
  • 21
2 votes
Accepted

How to get all Wikidata items in a country?

This query does the trick: SELECT DISTINCT ?item WHERE { ?item wdt:P131*/wdt:P17 wd:Q1014. # country: Liberia (recursive) ?item wdt:P31 wd:Q3917681. # instance of: embassy ?...
Nicolas Raoul's user avatar
  • 8,416

Only top scored, non community-wiki answers of a minimum length are eligible