Skip to main content
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,466
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

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
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
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,466
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

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

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

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
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
Accepted

Numerically order SPARQL results that are external identifiers but actually all numbers

As tipped by Stanislav Kralin and Barry Carter, ORDER BY xsd:integer( is the solution: SELECT ?rfcId ?itemLabel ?classLabel ?item WHERE { ?item wdt:P31 ?class. ?item wdt:P892 ?rfcId. SERVICE ...
Nicolas Raoul's user avatar
  • 8,466
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

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
  • 276
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,466
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
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,761
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
  • 869
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,466
2 votes
Accepted

Julian and Gregorian dates from Wikidata

As of April 2018, there is no way (in SPARQL). The RDF Dump format says: Note that the calendar model is the original values calendar model even if wikibase:timeValue was converted to Gregorian. ...
Stanislav Kralin's user avatar
2 votes

get item's properties know QID

Here's a SPARQL query that returns the properties that have a value for Q302 (limit 100 for speed). In your orignal queries, I think filtering on English is one reason there are no results. prefix ...
philshem's user avatar
  • 17.6k
2 votes
Accepted

Get list of all wikidata properties used to link to an item

The first part of my question is, is there a SPARQL equivalent of the "What links here" link? The second part of my question is how can I get a list of all unique properties that are used to ...
Stanislav Kralin's user avatar
2 votes

How to output only English labels in SPARQL query?

Is it producing a row of output in every language? Yes, you're correct: ?itemLabel match labels in all languages. Try simply SELECT * {?item rdfs:label "Mozilla Firefox"@en}. If you want to ...
Stanislav Kralin's user avatar
2 votes
Accepted

Wikidata SPARQL get current VALUES index

VALUES are unordered; SPARQL list syntax is also not allowed in VALUES. The simplest option is explicit ordering: SELECT ?index ?currentQid ?propQid ?targetQid WHERE { VALUES (?current ?index) {(...
Stanislav Kralin's user avatar

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