0

So, I am building an application, where I am displaying information in the database about subjects, and in the database, there is a link on wikipedia to the subject.

Now, we want to build multi-lingual interface to the app (to add French). and we have a French version for our main data. But for wikipedia links, we have only English links.

but wikipedia itself, on the page of a subject there are links to the same subject with different languages.

So, for example, Napoleon Bonaparte has this English page on wikipedia http://en.wikipedia.org/wiki/Napoleon

But if you visit that page, you will see links to other languages on Napoleon, and there is a link for French like this

http://fr.wikipedia.org/wiki/Napol%C3%A9on_Ier

So, is there a programmatic way to access the French url if we know the English?

2

3 Answers 3

0

I am pretty sure there's a wikipedia-api way to do this, but I couldn't resist posting a Freebase answer. Using the mqlread API and the following MQL:

{
  "en:key": {
    "namespace": "/wikipedia/en",
    "value": "Lake"
  },
  "fr:key": {
    "namespace": "/wikipedia/fr",
    "value": null,
    "limit": 1
  }
}

... you can get what you want. The MQL basically says: "given the /wikipedia/en/Lake object, what is the same object in the /wikipedia/fr namespace? The answer is of course /wikipedia/fr/Lac

In REST, this is:

https://www.googleapis.com/freebase/v1/mqlread?query={ "en:key": { "namespace": "/wikipedia/en", "value": "Lake" }, "fr:key": { "namespace": "/wikipedia/fr", "value": null, "limit": 1 } }

(non-escaped, and with spaces, for clarity)

And the response:

{"result": {"en:key": {"value": "Lake", "namespace": "/wikipedia/en"}, "fr:key": {"value": Lac", "namespace": "/wikipedia/fr"}}}

... so you want response["result"]["fr:key"]["value"]

Some notes:

  1. Make sure to get an API key from Google for any non-testing use. Otherwise you'll be sharing quota with everyone else and it couldn't run out at any time. Read more here: https://developers.google.com/freebase/v1/mqlread

  2. You will need to properly URI-escape your query part, of course.

  3. Within the value for "query", strings that contain non-printables (and some printables are well, such as comma, parens etc) will need to be escaped "the Freebase way": using a dollar sign and 4 hex digits, such that "(" become "$0028".

  4. You will need to do the reverse un-escaping in the response strings, of course.

Good luck!

0

The interwiki links are now stored in Wikidata. e.g. http://www.wikidata.org/wiki/Q517 You can either access them using the MediaWiki API or download the Wikidata dump. http://www.wikidata.org/wiki/Wikidata:Data_access

The Freebase API is good if you also need other information from Freebase, but if you just want the interwiki links getting it directly will give you more complete coverage (148 language Wikipedias vs ~30 in Freebase)

-1

Well, sometimes the only thing that changes from the links is the shortcut for the language for example:

http://en.wikipedia.org/wiki/Steve_jobs

http://fr.wikipedia.org/wiki/Steve_Jobs

The upper/lower case 'J' is not making the difference by accessing the site, because calling http://fr.wikipedia.org/wiki/Steve_jobs is successful anyway..

But for everything that's not a personality on Wikipedia the probability to not have similar links like those above is big.

Is your database big? If it's not too big I would put in the links manually, because finally that's more efficient than a big algorithm for such a "dumb" case.

1
  • thanks but we have more than 200000 subjects, and lots of them have total different link than English ones. I was hoping for some REST API or something simple. Aug 30, 2013 at 3:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.