How to gather Freebase Aliases for type location/location? - freebase

I'd like to pull information (MID and US English name) about all locations in Freebase AND also their Korean names and any Korean aliases via an MQL query. This is as far as I've gotten:
[{
"id": null,
"name": null,
"mid": null,
"type": "/location/location",
"Korean:name": [{
"lang": "/lang/ko",
"value": null
}]
}]
I'm only getting the Korean name, but not any Korean aliases. I don't know how to write a query that outputs properties of 2 different types in the same query. Can you get data about both /location/location AND common/topic/alias for the same entity in the same MQL query/output? Is my approach just wrong here?
Any help appreciated.

When you need to combine properties from many different types you need to use the fully qualified property ID like this:
[{
"id": null,
"name": null,
"mid": null,
"type": "/location/location",
"Korean:name": [{
"lang": "/lang/ko",
"value": null
}],
"/common/topic/alias": [{
"lang": "/lang/ko",
"value": null,
"optional": true
}]
}]
Whenever you use shortened property IDs they are assumed to be in the same type as the type you specify in your query (or /type/object if no type is given). So for example, if you were to use "geolocation" in your query it would be interpreted as "/location/location/geolocation". The only excepts are "id", "name" and "type" which you can use without using the full IDs eg. "/type/object/name".
You'll also note that I made aliases "optional" so that it would return results for locations that don't have any aliases.

Related

Freebase - query media_common on book_edition to get /book/book?

a complete beginner with freebase here, trying to understand how to make a query to find a /book/book by /book_edition/media_common/cataloged_instance/isbn13.
I tried this query and got this error: Type /book/book_edition does not have property media_common:
[{
"type": "/book/book",
"editions": [{
"media_common": [{
"cataloged_instance": [{
"isbn13": "9780812519112" //example isbn13 from ender's game - https://www.freebase.com/m/04v8gr6
}]
}]
}],
"id": null
}]
EDIT: this is the query I used to get the deprecated ISBN field on book_edition
[{
"type": "/book/book",
"editions": [{
"ISBN": "0312932081"
}],
"id": null
}]
The property is actually /media_common/cataloged_instance/isbn13 which you can discover by exploring the schema. Because it's from a different type than the expected type of /book/book/editions (which is /book/book_edition you need to use the fully qualified name. Ditto for the author property I added to the query below.
[{
"type": "/book/book",
"editions": [{
"/media_common/cataloged_instance/isbn13": "9780812519112"
}],
"id": null,
"name": null,
"/book/written_work/author": null
}]
without using the shorthand notation that allows us to drop type prefixes on property names, this query would look like:
[{
"/book/book/editions": [{
"/media_common/cataloged_instance/isbn13": "9780812519112"
}],
"/type/object/id": null,
"/type/object/name": null,
"/book/written_work/author": null
}]
The expansion of the property names to their fully qualified versions gets done mechanically by the query processor without any real knowledge of the schema. Conversely, graph traversal treats the property names as opaque strings.

/film/film/runtime always returns null

Whenever I try to query for the length of a film I get lists of null. The query I use is directly from the "Build query" button on their site and looks like this:
[{
"id": null,
"name": null,
"type": "/film/film",
"/film/film/runtime": []
}]
Ufortunately all the responses I get look like this:
{
"name": "4D Man",
"type": "/film/film",
"/film/film/runtime": [
null
],
"id": "/en/4d_man"
}
I can hover over the links you can see on the query page and see the runtime (in this case 85 minutes) but as you can see all I get from the query is null. This may be a Freebase bug, but any help is appreciated. Thank you.
There's not a single runtime of a film, the same film can have different runtimes (original version, director's cut, etc...) Freebase use the film_cut type to contain the different runtimes of a movie
You can use this query to get the runtimes:
[{
"id": null,
"name": null,
"/film/film/runtime": [{
"runtime": null
}]
}]
Tune this query to your needs, you may need type_of_film_cut or film_release_region.

Freebase MQL Query

I have a couple of questions.
I have a MQL query that gets some movie information. The trimmed query looks like this.
[{
"id": "/en/a_beautiful_mind",
"name": null,
"type": "/film/film",
"/common/topic/article": [{
"id": null,
"optional": true,
"limit": 3
}]
}]
it works just fine, I can retrieve the ID but is there a way to also get the article text without having to run a separate text query?
Second is I am trying to figure out how to get the featured song performer. I can do this and get the songs name.
[{
"id": "/en/a_beautiful_mind",
"name": null,
"type": "/film/film",
"featured_song": [{
"name": null,
"optional": true
}],
}]
But cant seem to figure out how to get the songs performer. Is it possible?
thanks for the help
Scott
One simple way to get this type of information about a film is to use the Topic API like this:
https://www.googleapis.com/freebase/v1/topic/en/a_beautiful_mind?filter=suggest&filter=/film/film
This won't get the featured song artist though. At least not without an additional API call. To do that in MQL you just nest additional queries inside the featured song like this:
[{
"id": "/en/a_beautiful_mind",
"name": null,
"type": "/film/film",
"featured_song": [{
"name": null,
"/music/recording/artist": [{}],
"/film/film_featured_song/performed_by": [{}],
"optional": true
}]
}]
Note that I've added two separate properties one for the artist who originally recorded the song and one for the artist who performed it in the film. In this case, the second property is empty implying that the original recording was used. Since I'm mixing properties from different types I need to use the fully-qualified property names.
All Freebase types are documented in the graph so you can look up types like /music/recording and /film/film_featured_song to see how they are meant to be used.

List properties of several types in MQL query

Good day!
I want to obtain information about several disasters. So, I ask this query:
[{
"type": "/event/disaster",
"*": null,
"limit": 10
}]
Ok, but I also need /time/event properties such as start_date. I'm trying this:
[{
"type": "/event/disaster",
"type": "/time/event",
"*": null,
"limit": 10
}]
and again got only /event/disaster properties because type : time/event inherently translated to "ns0:type". I've tried also this:
[{
"type": ["/event/disaster", /time/event"],
"*": null,
"limit": 10
}]
but got error. How I should formulate the query?
The MQL property wildcard (*) can only be applied to one type so you'll need to individually list the properties that you want to see like this:
[{
"type": "/event/disaster",
"/time/event/start_date": null,
"*": null,
"limit": 10
}]
Another way to do this would be to use the Search API to specify which property values to return (by type or domain) like this:
?filter=(all type:/event/disaster)
&output=(all:/event/disaster all:/time/event)

Freebase: Get name & Wikipedia ID in one query in a certain language

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)?
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.
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
}
}]

Resources