Krzysztof
Krzysztof

Reputation: 41

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 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?

Upvotes: 4

Views: 3650

Answers (4)

Karl Bartel
Karl Bartel

Reputation: 3434

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.

Upvotes: 2

Justin D. Harris
Justin D. Harris

Reputation: 2275

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.

Upvotes: 2

Karl Bartel
Karl Bartel

Reputation: 3434

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

Upvotes: 6

Sam Starling
Sam Starling

Reputation: 5378

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.

Upvotes: 1

Related Questions