wikionary API - 单词的含义 [英] wikionary API - meaning of words

查看:25
本文介绍了wikionary API - 单词的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 wikionary API 获取所选单词的含义.内容检索数据应与今日词"中呈现的相同,只有基本含义,没有词源、同义词等.例如

"邮政编码任何戴在头上或脸上的假头发,例如假胡须或假发."

我尝试使用文档,但我可以找到类似的例子,有人可以帮助解决这个问题吗?

解决方案

虽然 MediaWiki 有一个 API (api.php),但对于您的目的来说,使用 action 可能是最简单的index.php 的 =raw 参数,如果您只想检索一个修订版的源代码(而不是封装在 XML、JSON 等中,而不是封装在 API 中).

例如,这是 11 月 14 日当天页面的原始词:

http://en.wiktionary.org/w/index.php?title=Wiktionary:Word_of_the_day/November_14&action=raw

不幸的是,wiki 页面的格式侧重于呈现(对于人类读者)而不是语义(对于机器),因此您不应该对没有获取单词定义"API 命令感到惊讶.相反,您的脚本必须理解维基词典编辑器创建和使用的众多文本格式模板,以及复杂的表示格式语法,包括标题、无序列表等.例如,这里是页面溢出"的源代码:

http://en.wiktionary.org/w/index.php?title=overflow&action=raw

API 中有一个生成 XML 解析树"选项,但它并没有将大部分表示格式分解为 XML.自己看看吧:

http://en.wiktionary.org/w/api.php?action=query&titles=overflow&prop=revisions&rvprop=content&rvgeneratexml=&format=jsonfm

如果您想知道是否存在用于 MediaWiki 格式页面而不是 MediaWiki 的解析器,不,不存在.至少不是当前维护的任何用 JavaScript 编写的内容(请参阅替代解析器列表,并查看网络列出的两个网站).即便如此,支持大多数/所有通用模板也将是一个巨大的挑战.祝你好运.

I would like get meaning of selected word using wikionary API. Content retrieve data should be the same as is presented in "Word of the day", only the basic meaning without etympology, Synonyms etc.. for example

"postiche n Any item of false hair worn on the head or face, such as a false beard or wig."

I tried use documentation but i can find similar example, can anybody help with this problem?

解决方案

Although MediaWiki has an API (api.php), it might be easiest for your purposes to just use the action=raw parameter to index.php if you just want to retrieve the source code of one revision (not wrapped in XML, JSON, etc., as opposed to the API).

For example, this is the raw word of the day page for November 14:

http://en.wiktionary.org/w/index.php?title=Wiktionary:Word_of_the_day/November_14&action=raw

What's unfortunate is that the format of wiki pages focuses on presentation (for the human reader) rather than on semantics (for the machine), so you should not be surprised that there is no "get word definition" API command. Instead, your script will have to make sense of the numerous text formatting templates that Wiktionary editors have created and used, as well as complex presentational formatting syntax, including headings, unordered lists, and others. For example, here is the source code for the page "overflow":

http://en.wiktionary.org/w/index.php?title=overflow&action=raw

There is a "generate XML parse tree" option in the API, but it doesn't break much of the presentational formatting into XML. Just see for yourself:

http://en.wiktionary.org/w/api.php?action=query&titles=overflow&prop=revisions&rvprop=content&rvgeneratexml=&format=jsonfm

In case you are wondering whether there exists a parser for MediaWiki-format pages other than MediaWiki, no, there isn't. At least not anything written in JavaScript that's currently maintained (see list of alternative parsers, and check the web sites of the two listed ones). And even then, supporting most/all of the common templates will be a big challenge. Good luck.

这篇关于wikionary API - 单词的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆