0

I'm looking for a simple way to get data about a university (name, native_name, city etc) from the Wikipedia infobox after a user selects a university from Freebase suggest. The dataset returned from freebase, however, is very small and doesn't include the wikipedia link unfortunately.

Currently I am using the "name" property and making an ajax request to http://live.dbpedia.org/data/"+name+".json. This often works but while doing some tests it turned out the name doesn't always map directly to the correct page. Let me split my question in a few to make myself clear:

  • Is it possible to configure the Freebase suggest plugin so that the response includes the wikipedia link?

  • OR is there a similar plugin that queries DBpedia directly and is as simple and user-friendly as Freebase's?

  • OR, as a plan B, is there a way to send a request to "live.dbpedia.org" so that it only returns me the json after redirects? On the Wikipedia API I can send a "redirects" variable that does this. But then I'd have to parse the data myself…

The problem with the plan B is that nothing guarantees that the freebase object's name will ever lead me to the correct Wikipedia page. Even after the redirects…

I swear I've read a lot of API documentation but everything is extremely confusing and I chose not to read long tutorials about RDF, SPARQL and MQL because I really don't think the solution should be so complicated. I'm asking here because I really hope I'm missing a simple solution…

UPDATE

{
  id: "/en/babes-bolyai_university",
  lang: "en",
  mid: "/m/08c4bf",
  name: "Babeş-Bolyai University",
  notable: {
    id: "/education/university",
    name: "College/University"
  },
  score: 37.733559
}

This is the result I get after selecting "Babeş-Bolyai University" in the suggest widget.

SOLUTION

I assumed I can't configure the Suggest widget to return more data, so after getting the Freebase ID of the object I just send another request, this time with a query specifically asking for the Wikipedia ID. I didn't know any MQL and couldn't find the name of the Freebase field with the Wikipedia ID. Maybe I'm stupid but the Freebase documentation really confuses me. In any case Tom Morris' answer and this question helped me build the query that returned what I wanted:

https://www.googleapis.com/freebase/v1/mqlread?query={"id":"/en/babes-bolyai_university","key":{"namespace":"/wikipedia/en_title","value":null}}

The strings in the result come with numeric codes for special unicode characters though (in my case Babe$0219-Bolyai_University). I've been able to convert the code with String.fromCharCode(parseInt(219, 16)) but if someone knows of a way to convert the whole string that would be helpful. Otherwise I can just make my own function replacing the "$dddd" pattern with the corresponding character.

Thanks for the help!

Community
  • 1
  • 1
Ariel
  • 3,383
  • 4
  • 43
  • 58
  • For those of us less familiar with Freebase, can you should the data that you're getting from Freebase (e.g., that contains the `name` that you mentioned)? – Joshua Taylor Feb 27 '14 at 12:42
  • I haven't used Freebase much, but in browsing some of the data, e.g., http://www.freebase.com/m/09rgp, I see that there is a "topic equivalent webpage" property, and that some of its values are wikipedia links. Would it be possible to extract, e.g., `Road_bicycle` from `http://en.wikipedia.org/wiki/Road_bicycle` and use that rather than a name property? – Joshua Taylor Feb 27 '14 at 12:49
  • It would be helpful if you gave an example of a Freebase topic and the property/infobox value that you are unable to get. That would help ground the discussion. – Tom Morris Feb 27 '14 at 13:50

2 Answers2

0

There isn't a DBpedia autosuggest comparable to Freebase Suggest as far as I'm aware.

Anything that's in Freebase can be retrieved with Suggest by using an MQL expressions in the output parameter. For simple things, e.g. names, aliases, the MQL is basically just a JSON snippet containing the relevant property name.

EDIT: The output parameter doesn't actually appear to be documented in the context of Suggest, but anything that isn't a Suggest parameter gets passed through transparently to the Freebase Search API, so you can use all of the stuff described here: https://developers.google.com/freebase/v1/search-output You can get as much or as little information as you require returned with each suggestion.

If you do need to query DBpedia, you should be using the Wikipedia/DBpedia key, which is not necessarily the same as the name. For English Wikipedia, the key is in the namespace /wikipedia/en or if you want the numeric Wikipedia ID in the namespace `/wikipedia/en_id'. Replace the 'en' with the appropriate language code if you want to query other language Wikipedias. These keys have some non-ASCII characters escaped, so if you need to unescape them, you can use the documentation here: http://wiki.freebase.com/wiki/MQL_key_escaping

Tom Morris
  • 10,490
  • 32
  • 53
  • I know the information is on Freebase, it just isn't in the object returned by the suggestion widget. I was wondering if I could configure the widget to return more info so I didn't have to make another request just for the Wikipedia id, but I guess this was a silly preoccupation considering that I'm probably sending requests on every keyup event on the suggest widget's input field anyway. One extra query shouldn't do any harm :) – Ariel Feb 28 '14 at 07:58
  • There's no need to do an extra query. I've revised my answer to focus more on retrieving information from Freebase now that I know that's what you want to do. I also added a link to the documentation for how to handle key escaping. – Tom Morris Feb 28 '14 at 15:13
  • I added the output parameter to my query (`&output=(/wikipedia/en_title)`) but I'm getting `"error evaluating 'output' parameter: Property not found: /wikipedia/en_title"` – Ariel Mar 02 '14 at 09:20
  • That's because it's a namespace, not a property. The property name (from memory, so double check) is `/type/object/key` – Tom Morris Mar 13 '14 at 14:47
0

You can update the "flyout_service_path" parameter. Here there is a description in the freebase suggest documentation (https://developers.google.com/freebase/v1/suggest). I'm using this configuration for to get all the keys of a entity.

 $(inputClass).suggest(
            {
                "key" : _FREEBASE_API_KEY_BROWSER_APP,
                "flyout_service_path":"/search?filter=(all mid:${id})&output=(notable:/client/summary description type /type/object/key)&key=${key}"
            }
        ).bind("fb-select", this.fbSelectedHandler);

In the freebase response I can see now in the "output" parameter the "/type/object/key" with all the keys of the entity (wikipedia,etc..).

My question now is how I can acquire this data from output ?. In the "fb-select" event the "data" variable, don't carry this fields.

Some help, please..

rub3n_lh
  • 49
  • 5