问题描述
我对 API 完全陌生,如果问题很愚蠢,请见谅.
我想在 Commons 中获得一个类别中的所有图像,假设 X,但排除那些也在另一个(Y)中的图像.我不明白我是否真的可以做到这一点.
考虑以下查询 URL:
https://fastcci.wmflabs.org/?c1=3302993&c2=15516712&d1=0&d2=0&s=200&a=not&t=js
- https://fastcci.wmflabs.org/ - 托管 Wikimedia Commons fastcci 运行
- c1 - 类别 1 的 ID
- c2 - 类别 2 的 ID
- d1 - 要搜索的类别 1 的深度(fastcci 默认考虑子类别)
- d2 - 要搜索的类别 2 的深度(fastcci 默认考虑子类别)
- s - 要返回的数字或结果
- o - 偏移
- a - 连词
- t - 连接类型(
t=js
用于 JSONP 响应;否则假定用作 websocket)
回复
fastcciCallback( [ '结果 27572680,0,0|1675043,0,0|27577015,0,0|27577043,0,0|27577106,0,0|27576896,0,6920|,0|23481936,0,0|17560964,0,0|11009066,0,0', 'OUTOF 10', 'DBAGE 378310', 'DONE'] );
RESULT
后跟 |
分隔的列表,最多 50 个整数三元组,形式为 pageId,depth,tag
.每个三元组代表一个图像或类别
资源
- 示例客户端实现 - 看看它的实际效果,只需访问任何类别并在
好图片
按钮旁边在任何类别页面.- 示例为
FilesOf('Category:Saaleck')
-FilesOf('Category:Rapeseed fields in Saxony-Anhalt')
- 示例为
- 服务器应用程序
- YouTube 上的演示文稿
- 幻灯片
关于 pageID 的说明
- 页面 ID → 页面标题:
GET
/w/api.php?action=query&pageids=page_IDs_separated_by_pipe
- 页面标题 → 页面 ID:
GET
/w/api.php?action=query&titles=Titles_separated_by_pipe
I am entirely new to API, so sorry if the question is silly.
I would like to get all images in a category in Commons let's say X, but exclude those which are also in another one (Y). I do not understand if I can actually do this.
will get all of them, how to exclude some?
moreover I would like in the result to have the description of the images, not just the name of the file, is that possible?
MediaWiki has - by default - no built-in support for category building and querying intersections. To accomplish this task, extensions or external tools or multiple API queries and result processing is required.
CirrusSearch API
On Wikimedia Commons, like on the whole Wikimedia Wiki farm, CirrusSearch powers filtered search, including search for category intersections and is also available through API (action=query&list=search&srsearch=incategory:A+-incategory:B
, this is Category:A
minus Category:B
).
FastCCI
One of the tools I can recommend (because it's a dedicated high-performance solution and actually running) is fastcci, developed by Daniel Schwen; specifically for Wikimedia Commons, there is already a database maintained and a webservice running but it's possible to set it up for any wiki, provided the tool set has a host to run on and has database access.
Query
Consider the following query URL:
https://fastcci.wmflabs.org/?c1=3302993&c2=15516712&d1=0&d2=0&s=200&a=not&t=js
- https://fastcci.wmflabs.org/ - Host Wikimedia Commons fastcci runs on
- c1 - ID of category 1
- c2 - ID of category 2
- d1 - depth of category 1 to search in (fastcci by default considers sub-categories)
- d2 - depth of category 2 to search in (fastcci by default considers sub-categories)
- s - Number or results to return
- o - Offset
- a - conjunction
- t - connection type (
t=js
for a JSONP response; otherwise assumes being used as websocket)
Response
fastcciCallback( [ 'RESULT 27572680,0,0|1675043,0,0|27577015,0,0|27577043,0,0|27577106,0,0|27576896,0,0|27576790,0,0|23481936,0,0|17560964,0,0|11009066,0,0', 'OUTOF 10', 'DBAGE 378310', 'DONE'] );
RESULT
followed by a |
separated list of up to 50 integer triplets of the form pageId,depth,tag
. Each triplet stands for one image or category
Resources
- Sample client side implementation - to see it in action, just visit any category and next to the
Good pictures
button in any category page.- Example is
FilesOf('Category:Saaleck')
-FilesOf('Category:Rapeseed fields in Saxony-Anhalt')
- Example is
- Server application
- Presentation on YouTube
- Slides
A note on pageIDs
- page IDs → page titles:
GET
/w/api.php?action=query&pageids=page_IDs_separated_by_pipe
- page titles → page IDs:
GET
/w/api.php?action=query&titles=Titles_separated_by_pipe
这篇关于如何使用 Mediawiki API 获取一个类别中不属于另一个类别的所有图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!