Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get list of statements for a given Wikidata ID?

The only thing I managed to do is this link:

https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q568&format=jsonfm

But this produces lots of useless data. What I need is to get all the statements for the given item, but I can't see any of the statements in the query above.

here it will be:

{ "instance of" : "chemical element",
  "element symbol" : "Li",
  "atomic number" : 3,
  "oxidation state" : 1,
  "subclass of" : ["chemical element", "alkali metal"]
 // etc...
}

Is there an API for this or must I scrape the web page?

like image 492
rsk82 Avatar asked Oct 02 '22 10:10

rsk82


1 Answers

The information you want is in your query, except it's hard to decode. For example, this:

"P246": [
          {
            "id": "q568$E47B8CE7-C91D-484A-9DA4-6153F132997D",
            "mainsnak": {
              "snaktype": "value",
              "property": "P246",
              "datatype": "string",
              "datavalue": {
                "value": "Li",
                "type": "string"
              }
            },
            "type": "statement",
            "rank": "normal",
            "references": …
          }
        ]

means that the “element symbol” (property P246) is “Li”. So, you will need to read all the properties from your query and then find out the name for each of the properties you found.

To get just the statements, you could also use action=wbgetclaims, but it's in the same format as above.

like image 79
svick Avatar answered Oct 05 '22 13:10

svick