开发者

Retrieving the translation section in the Wiktionary API

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 sec开发者_StackOverflow中文版tion 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?


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/ .


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜