本文介绍了如何使用 Mediawiki API 获取一个类别中不属于另一个类别的所有图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 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.每个三元组代表一个图像或类别

资源

关于 pageID 的说明

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.

https://commons.wikimedia.org/w/api.php?action=query&list=categorymembers&cmtype=file&cmtitle=Category:X

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

A note on pageIDs

这篇关于如何使用 Mediawiki API 获取一个类别中不属于另一个类别的所有图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 23:59