Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all Wikidata items that are an instance of a given item

Wikidata has an item called smartphone model.
I want to get all instances of it.

QUESTION: How to get the identifiers of the instances programmatically, using the live server?

Preferably not including false positives that show up in WhatLinksHere but are in the "Wikidata:" namespace rather than the main namespace.

like image 407
Nicolas Raoul Avatar asked Apr 27 '15 02:04

Nicolas Raoul


People also ask

How do I find Wikidata?

In the query.wikidata.org query editor, you can press Ctrl + Space (or Alt + Enter or Ctrl + Alt + Enter ) at any point in the query and get suggestions for code that might be appropriate; select the right suggestion with the up / down arrow keys, and press Enter to select it.

What is Wikidata item?

In Wikidata, items are used to represent all the things in human knowledge, including topics, concepts, and objects. For example, the "1988 Summer Olympics", "love", "Elvis Presley", and "gorilla" are all items in Wikidata.

Is Wikidata credible?

Is Wikidata Reliable? Wikidata has a number of measures to ensure that its data are reliable. There is the option to add a reference to any entry on Wikidata, and users are encouraged to do so for the integrity of the website. In addition, institutions are supporting the reliability of Wikidata.

What is the point of Wikidata?

Wikidata is the centralized, linked data repository for all Wikimedia projects. This means that all Wikimedia projects (Commons and Wikipedia for instance) can pull the information from the same central place. This also means that all 300+ language versions of Wikipedia can pull data from Wikidata as well.


1 Answers

Your question specifies the "Mediawiki API" but this is not possible.

Wikidata has a SPARQL query service at https://query.wikidata.org

The query that you want is:

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>

SELECT DISTINCT ?item
WHERE {
    ?item wdt:P31/wdt:P279* wd:Q19723451
}

This will list the Items that are an 'instance of'(P31) 'smartphone model'(Q19723451) or an 'instance of' a 'subclass of'(P279) 'smartphone model'(Q19723451).

like image 60
Addshore Avatar answered Oct 11 '22 13:10

Addshore