Ware Ware - 1 month ago 11
Java Question

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

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.

Answer

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