我有兴趣将英语单词翻译成特定语言(例如俄语)。我已经阅读了整个维基词典API手册,但我还没有找到一个好的方法。对于单词“dog”,我可以通过以下方式使用维基词典 API 来获取包含其他语言翻译的整个部分:
http://en.wiktionary.org/w/api.php?action=query&titles=dog&prop=revisions&rvprop=content&rvsection=11
翻译部分的编号不是恒定的,并且对于不同的单词来说是不同的。对于“dog”,翻译节号是 11
,但对于“cat”,我需要 rvsection=7
。是否可以在不下载整个翻译部分的情况下获得任何英语单词的特定语言的翻译?
I am interested in translating English words to a specific language (e.g. Russian). I have read the whole Wiktionary API manual but I have not found a good way. For the word “dog” I can obtain the whole section that contains translations to other languages, by using the wiktionary API in the following way:
http://en.wiktionary.org/w/api.php?action=query&titles=dog&prop=revisions&rvprop=content&rvsection=11
The translations section number is not constant and it is different for various words. For “dog” the translation section number is 11
but for “cat” I need rvsection=7
. Is it possible to obtain a translation to a specific language for any English word without downloading the whole translation section?
发布评论
评论(4)
通过从 API 请求跨维基链接,您可以获得相当多的翻译。我使用这种方法编写了一个简单的JS应用程序: http://jsfiddle.net/karlb/PxfrJ/11 / 。
You can get quite a lot of the translations by requesting the interwiki links from the API. I have written a simple JS app using this approach: http://jsfiddle.net/karlb/PxfrJ/11/ .
您可以使用它帮助将“狗”从英语翻译成俄语。此 URL 查找标题为“dog”的页面以“ru”开头的内部链接: https://en.wiktionary.org/w/api.php?action=query&prop=iwlinks&titles=dog&iwprop=url&iwprefix=ru&format=json&继续=
我强调帮助,因为您会得到许多不明确的翻译,您可能需要使用类别和其他东西来消除歧义。
该 URL 具有“iwprop=url”,因此您可以轻松单击链接,但在您的应用程序中我建议您使用此:
https://en.wiktionary.org/w/api.php?action=query&prop=iwlinks&titles=dog&iwprefix=ru&format=json&continue=
并自己制作链接。
You can use this to help translate "dog" from English to Russian. This URL finds the internal links that start with "ru" for pages with the title "dog" : https://en.wiktionary.org/w/api.php?action=query&prop=iwlinks&titles=dog&iwprop=url&iwprefix=ru&format=json&continue=
I emphasize help because you will get many ambiguous translations which you might want to disambiguate using categories and other things.
That URL has "iwprop=url" so you can easily click the links but in your application I suggest you use this:
https://en.wiktionary.org/w/api.php?action=query&prop=iwlinks&titles=dog&iwprefix=ru&format=json&continue=
and make the links yourself.
dbpedia 和 Dbnary 项目从 Wiktionary 中提取翻译数据作为 RDF,并提供一个 SPARQL 端点,您可以在其中查询翻译,而无需下载大型数据集。
以下是 Dbnary 的查询示例:
导致 这些结果。
The dbpedia and Dbnary projects extract translation data from Wiktionary as RDF and provide a SPARQL endpoint where you can query translations without needing to download large data sets.
Here's a query example for Dbnary:
Which leads to these results.
维基词典 API 不会在两种语言之间对某个单词进行特定翻译。在这里不可能做你想做的事。
不过,Google 翻译确实有API 可以满足您的需求。
The Wiktionary API won't do specific translations of one word between two languages. It's not possible to do what you are wanting to do here.
However, Google Translate does have an API that can do what you're looking for.