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

纵然是瞬间 提交于 2019-12-22 07:46:25

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/22175896/how-to-get-list-of-statements-for-a-given-wikidata-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!