Question

Is it possible to do one query in MQL to obtain the name and the wikipedia ID for a certain language from Freebase? If that's possible, is it also possible to do this for a set of languages (eg. german & english)?

Was it helpful?

Solution

Asked and answered, but here's a slightly better form of the query:

[{
  "id": "/en/white_house",
  "mid": null,
  "de:name": {
    "lang": "/lang/de",
    "value": null
  },
  "en:name": null,
  "wiki_de:key": {
    "/type/key/namespace": "/wikipedia/de_id",
    "value":         null,
    "optional": True,
  },
  "wiki_en:key": {
    "/type/key/namespace": "/wikipedia/en_id",
    "value":         null,
    "optional": True,
  }
}]​

The Wikipedia keys will be escaped if they contain special characters, so you should consult http://wiki.freebase.com/wiki/MQL_key_escaping for how to unescape them.

Some of the reasons this query is better include:

  • English is the default language, so it doesn't need to be specified for names
  • it removes the ambiguity of the namespace lookup. Your original query is actually looking for the key "white_house" in any namespace (and finding it in "/en" which is equivalent to the id "/en/white_house")

Note that you don't need to do the lookup by ID. You can use any lookup facility that MQL provides such as looking up by one of the Wikipedia keys or using "name~=":"white house" to find all topics containing that string or anything else that works for your starting data and your use case.

OTHER TIPS

After playing around with MQL I finally came up with the following query (for white_house):

[{
  "id": null,
  "mid": null,
  "de:name": {
    "lang": "/lang/de",
    "value": null
  },
  "en:name": {
    "lang": "/lang/en",
    "value": null
  },

  "key": {
    "value": "white_house"
  },
  "wiki_de:key": {
    "/type/key/namespace": "/wikipedia/de_id",
    "value":         null
  },
  "wiki_en:key": {
    "/type/key/namespace": "/wikipedia/en_id",
    "value":         null
  }
}]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top