检索维基词典 API 中的翻译部分

发布于 2024-11-30 19:30:06 字数 394 浏览 2 评论 0 原文

我有兴趣将英语单词翻译成特定语言(例如俄语)。我已经阅读了整个维基词典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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

老街孤人 2024-12-07 19:30:07

通过从 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/ .

山川志 2024-12-07 19:30:07

您可以使用它帮助将“狗”从英语翻译成俄语。此 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.

番薯 2024-12-07 19:30:07

dbpediaDbnary 项目从 Wiktionary 中提取翻译数据作为 RDF,并提供一个 SPARQL 端点,您可以在其中查询翻译,而无需下载大型数据集。

以下是 Dbnary 的查询示例:

SELECT DISTINCT ?written_trans AS ?translations
WHERE {
    ?lexentry ontolex:canonicalForm [
        ontolex:writtenRep "dog"@en
    ] .

    ?trans dbnary:isTranslationOf ?lexentry ;
           dbnary:targetLanguage lexvo:rus ;
           dbnary:writtenForm ?written_trans .
}

导致 这些结果。

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:

SELECT DISTINCT ?written_trans AS ?translations
WHERE {
    ?lexentry ontolex:canonicalForm [
        ontolex:writtenRep "dog"@en
    ] .

    ?trans dbnary:isTranslationOf ?lexentry ;
           dbnary:targetLanguage lexvo:rus ;
           dbnary:writtenForm ?written_trans .
}

Which leads to these results.

耳钉梦 2024-12-07 19:30:07

维基词典 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文