Ware Ware - 1 year ago 104
Java Question

How to get the Property 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",
"World Ocean",

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

Answer Source

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:


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

The last step is to create another request by using the same API with action wbgetentities:


where ids are the all numeric-ids from the previous step, prefixed with Q and separated by pipe |. This will return the all item labels in English:

    <entity id="Q459173"><label language="en" value="Challenger Deep" /></entity>
    <entity id="Q544"><label language="en" value="Solar System" /></entity>
    <entity id="Q3241540"><label language="en" value="oblate spheroid" /></entity>
    <entity id="Q185969"><label language="en" value="geoid" /></entity>
    <entity id="Q715269"><label language="en" value="World Ocean" /></entity>
    <entity id="Q27527"><label language="en" value="Afro-Eurasia" /></entity>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download