How collect Wikidata's entities by a certain property?
5 Answers
Assuming you are familiar with SPARQL, Wikidata (not to be confused with DBpedia) has an official endpoint and a page with example queries. The following example lists all countries with the property sovereign state:
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT ?cid ?country WHERE {
?cid wdt:P31 wd:Q3624078 .
OPTIONAL {
?cid rdfs:label ?country filter (lang(?country) = "en") .
}
}
For more information, please visit official reference for data access.
-
In this sample query, under current terminology "sovereign state" is not a property, but an Item. The property here is P31 (instanceOf). This query returns items that have a specific value of a given property, but not all items (which is a trivial extension of this query: opendata.stackexchange.com/a/21857/25882 ) Commented Dec 3 at 18:33
While not the most script-friendly, here is the easiest/fastest way to get what you want without any third-party:
1) Go to the Wikidata page of the property
2) Click What links here in the left panel's Tools section:
3) Enjoy the paged list:
You can do it by using MediaWiki API for Wikidata with backlinks query
https://www.wikidata.org/w/api.php?action=query&list=backlinks&blnamespace=0&bllimit=500&&bltitle=Property:P1086
In above example blnamespace=0 means the result list to include only items (without user pages, talk pages, templates, etc.). The example is for atomic number (P1086) property.
Depending on what property you are looking for (the question isn't that clear) you could use DBpedia and SPARQL any entities that have a connection with a certain link/property.
Let's see for the property P8329 (Principal Investigator), which is meant to state that some place has someone as its principal investigator.
To select all items that have the property "principal investigator" and also show the object of the statement you can use:
SELECT ?subject ?subjectLabel ?object ?objectLabel
WHERE
{
?subject wdt:P8329 ?object.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en". }
}
Sample row:
subject subjectLabel object objectLabel
wd:Q101552380 Cees Dekker Lab wd:Q330365 Cees Dekker
If you just want the places without repetition if they had multiple PIs, we can use DISTINCT
as in:
SELECT DISTINCT ?subject ?subjectLabel
WHERE
{
?subject wdt:P8329 ?object.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en". }
}