How to get all Property value's Labels of an Wikidata Item?
Asked Answered
J

1

6

How would you request the set of all Properties that an Item has?

Specifically, I'm looking for the English Labels for each Item that is the Value of an Item's Property.

E.g. "Earth":

{
    "Challenger Deep",
    "Solar System",
    "oblate spheroid",
    "geoid",
    "World Ocean",
    "Afro-Eurasia",
    ...
}

I'm using the Wikidata Toolkit library for now, but I'd take recommendations.

Jackass answered 15/1, 2016 at 16:7 Comment(0)
B
4

First you need to use MediaWiki API with action wbgetclaims to get all properties for each one claim. For example for Wikidata item Earth (Q2) the request will be:

https://www.wikidata.org/w/api.php?action=wbgetclaims&format=xml&props=value&entity=Q2

Then you need to parse the response and to take id from the value for each one property. In this example, for property P1589 the item id is Q459173.

The last step is to get all item labels in English by another request. You have two variants, in both of them we use the all item ids from the previous step, separated by pipe |:

Update: I found how to get all item property value's labels by using only one request. The idea is to find all item links, and then to filter from them only these from namespace 0 which start with Q.

https://www.wikidata.org/w/api.php?action=query&titles=Q2&generator=links&gplnamespace=0&gpllimit=100&prop=pageterms&wbptterms=label
Bolling answered 15/1, 2016 at 19:25 Comment(2)
but can I use Wikidata Query Service SPARQL for this?Mortality
now, it seems that you can directly use the id instead of the numeric-id: <value entity-type="item" numeric-id="459173" id="Q459173"/>Provencher

© 2022 - 2024 — McMap. All rights reserved.