Get depictions from Wikimedia Commons

巧了我就是萌 提交于 2019-12-13 04:26:45

问题


Wikimedia Commons has a new feature to describe what a picture depicts. Example:

Question

How to get the "depicts" of a given image, as JSON, using either a wikimedia-android-data-client library call or a REST HTTP request?


回答1:


You can use some of the Wikibase APIs (exactly which or how is not well-documented at the moment, I think). E.g.

https://commons.wikimedia.org/w/api.php?action=wbgetclaims&format=jsonfm&entity=M78893847

{
    "claims": {
        "P180": [
            {
                "mainsnak": {
                    "snaktype": "value",
                    "property": "P180",
                    "hash": "7754bb4b4dcf94dd0a6b8524351b22df21328a88",
                    "datavalue": {
                        "value": {
                            "entity-type": "item",
                            "numeric-id": 12280,
                            "id": "Q12280"
                        },
                        "type": "wikibase-entityid"
                    },
                    "datatype": "wikibase-item"
                },
                "type": "statement",
                "id": "M78893847$bf7f116a-4d08-0426-0e81-c9552a89fa63",
                "rank": "preferred"
            },
            {
                "mainsnak": {
                    "snaktype": "value",
                    "property": "P180",
                    "hash": "8ed7e126588c21d3cf88387d5ee875d528c00a74",
                    "datavalue": {
                        "value": {
                            "entity-type": "item",
                            "numeric-id": 1021645,
                            "id": "Q1021645"
                        },
                        "type": "wikibase-entityid"
                    },
                    "datatype": "wikibase-item"
                },
                "type": "statement",
                "id": "M78893847$7830fc04-4a1e-f289-93bc-69d6bbf3b7fd",
                "rank": "normal"
            }
        ]
    }
}

78893847 being the page ID which you can get via the query API: https://commons.wikimedia.org/w/api.php?action=query&format=jsonfm&formatversion=2&titles=File%3AMomoyo-brug%20in%20Shibaura%2C%20gezien%20richting%20het%20zuidoosten%2C%20-15%20maart%202019.jpg

{
    "batchcomplete": true,
    "query": {
        "pages": [
            {
                "pageid": 78893847,
                "ns": 6,
                "title": "File:Momoyo-brug in Shibaura, gezien richting het zuidoosten, -15 maart 2019.jpg"
            }
        ]
    }
}


来源:https://stackoverflow.com/questions/57156241/get-depictions-from-wikimedia-commons

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