Freebase not returning all available values - freebase

I'm trying to extract the link to the NYTimes Topic page (among the topic_equivalent_webpage values) for Barack Obama from Freebase, but my query doesn't return any results, although it's on the webpage (http://www.freebase.com/m/02mjmr). This is my query:
[{
"id": "/en/barack_obama",
"type": "/common/topic",
"topic_equivalent_webpage": {
"value": null,
"value~=": "*nytimes*"
}
}]
I've also tried extracting all of the topic_equivalent_webpage values instead, using this query:
[{
"id": "/en/barack_obama",
"type": "/common/topic",
"topic_equivalent_webpage": []
}]
For some reason it only returns one of the values (http://www.worldcat.org/wcidentities/lccn-n94-112934).
Does anyone have any tips?

NOTE: All Freebase APIs are going away in a few months.
You have three choices:
Download the RDF dump and filter it. This is most appropriate for a large-scale download instead of using the API. For the property name and decoding process, see #3.
Use the Topic API i.e. https://www.googleapis.com/freebase/v1/topic/en/barack_obama?filter=/common/topic/topic_equivalent_webpage
Query MQL for the keys in the namespace that you want (ie the NY Times namespace)
[{
"id": "/en/barack_obama",
"key": [{
"namespace": "/source/nytimes",
"value": null
}]
}]
Normally the result is an identifier that gets substituted into a URI template, but in the NYT case it's basically a full URI path that just gets appended to http://nytimes.com/
The key value (e.g. top$002Freference$002Ftimestopics$002Fpeople$002Fo$002Fbarack_obama) will be MQL key encoded, so they'll need to be decoded, but in this case you can probably cheat and replace all "$002F" substrings with "/". If any other characters are encoded, just replace $dddd with the character that has that Unicode code point.

Related

Freebase MQL must sort on a single value

I'm trying to learn to use Freebase, however when I try and do a sort by "/people/person/date_of_birth" for a search for actors for a show, it returns:
"code": 400,
"message": "Must sort on a single value, not at /tv/tv_program/regular_cast./tv/regular_tv_appearance/actor./people/person/date_of_birth"
Here is the full MQL query:
[{
"id": "/m/0524b41",
"name": [],
"sort":"/tv/tv_program/regular_cast./tv/regular_tv_appearance/actor./people/person/date_of_birth",
"/tv/tv_program/regular_cast": [{
"/tv/regular_tv_appearance/actor": [{
"name": [],
"/people/person/date_of_birth": []
}]
}]
}]
But you're not asking to sort on /people/person/date_of_birth, you're asking to sort on that long nested expression which goes through multiple intermediary nodes, some of which can appear multiple times (as indicated by the [] array notation). It's this multiplicity that MQL is complaining about.
To fix it, take your query, paste it into the query editor, click on the innermost /person/date_of_birth and then click "Invert Query." That will turn the query inside out and give you something that looks like this:
[{
"name": [],
"/people/person/date_of_birth": [],
"type": "/tv/tv_actor",
"!/tv/regular_tv_appearance/actor": [{
"!/tv/tv_program/regular_cast": [{
"id": "/m/0524b41",
"name": [],
"sort": "/tv/tv_program/regular_cast./tv/regular_tv_appearance/actor./people/person/date_of_birth"
}]
}]
}]
which isn't exactly what you want, but indicates the general shape of your target query.
Getting rid of the array brackets for single valued properties and moving the sort clause to the outside gives us:
[{
"name": null,
"/people/person/date_of_birth": null,
"sort": "/people/person/date_of_birth",
"type": "/tv/tv_actor",
"!/tv/regular_tv_appearance/actor": [{
"!/tv/tv_program/regular_cast": [{
"id": "/m/0524b41",
"name": null
}]
}]
}]
which is functional and returns our 81 regular Game of Thrones actors sorted by birth date, but could still be cleaned up a bit more. The !inverse property notation isn't necessary since we have forward equivalents and we don't really need to get the Game of Thrones info over and over again since it's constant and we really just want to use it as a filter.
Incorporating these final tweaks gives us a final query like this which returns nice compact results:
[{
"name": null,
"/people/person/date_of_birth": null,
"sort": "/people/person/date_of_birth",
"type": "/tv/tv_actor",
"starring_roles": [{
"series": {
"id": "/m/0524b41"
},
"limit": 0
}]
}]
The "limit": 0 clause is a little trick to cause MQL to use that subquery for filtering, but not bother returning any of the (constant) information in the results. The /tv/tv_actor/starring_roles and /tv/regular_tv_appearance/series can be abbreviated to the simple property names because their types are implied by their context.
Since there are only 81 results, MQL's default limit of 100 is plenty and we don't need to worry about increasing it or using cursors.
Oldest Game of Thrones actor: Peter Vaughn, born 1923.
Youngest: Lino Facioli b. 2000
Note that 7 actors don't have birth dates in Freebase, so we don't know where they rank age-wise. Here's a bonus query which returns their names and ids as well as their character's name. If we were running a production system, we might use something like this to feed a human curation queue to fill in the gaps.
[{
"name": null,
"/people/person/date_of_birth": {
"value": null,
"optional": "forbidden"
},
"type": "/tv/tv_actor",
"starring_roles": [{
"series": {
"id": "/m/0524b41"
},
"character":null
}]
}]
The seven character/actor pairs are (were): Roose Bolton - Michael McElhatton,
Gregor Clegane - Conan Stevens,
Hizdahr zo Loraq - Joel Fry,
Rickon Stark - Art Parkinson,
Janos Slynt - Dominic Carter,
Hodor - Kristian Nairn,
Tommen Baratheon - Callum Wharry. I say "were" because I couldn't resist fixing Hodor's birth date. The strange thing is that it was in Wikipedia, so should have been picked up automatically by Freebase. I think there's a bug lurking there somewhere.

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.

Freebase MQL query - Get data by a social link

I'm having a hard time trying to get data about a person from Freebase using his social link - by a MQL query.
How could this be done?
Something like:
https://www.googleapis.com/freebase/v1/mqlread?query={
"*":[{}],
"/common/topic/social_media_presence":[{
"value":"http://twitter.com/JustinBieber"
}]
}
Those links are really stored as keys and the links are generated from templates with they key plugged in. You can see all the keys here: https://www.freebase.com/m/06w2sn5?keys=
A modified version of your query would be:
[{
"key": [{
"namespace": {
"id": "/authority/twitter"
},
"value": "JustinBieber"
}],
"*": [{}]
}]
You can do the same thing with other namespaces like /authority/facebook or /authority/musicbrainz as well as the various language wikipedias e.g. /wikipedia/en
I'm not sure how complete the coverage or currency of the social media info is though...

Freebase Obtain All Information On One Subject

I'm trying to find the best way to get the information displayed on a Freebase page via a MQL query.
I've tried the topic API but that includes a lot of metadata.
I've also tried using links/reflection as in:
{
"id": "/en/samsung_electronics",
"/type/reflect/any_master": [{
"link": {
"master_property": null
},
"name": null,
"id": null
}],
"/type/reflect/any_reverse": [{
"link": {
"master_property": null
},
"name": null,
"id": null
}],
"/type/reflect/any_value": [{
"link": {
"master_property": null
},
"value": null
}]
}
But that means I'll be missing some information, such as the number of employees because that's given as a "Dated Integer" which, of course, doesn't get automatically expanded and I won't know what I would have to expand in general. My best attempts at expanding all objects by nesting that query once in itself were met with a
"code": 503,
"message": "Backend Error"
In RDF/SPARQL (e.g. DBpedia) I'd just do select ?p ?o where {URI ?p ?o} and select ?s ?p where {?s ?p URI}, am I missing such a simple way to do this in Freebase?
So to summarize, I'm looking for a way to get the information on a Freebase HTML page with as little overhead as possible and without missing anything.
The Topic API was designed specifically for this use case (and is what's used to construct the Freebase HTML page). It takes a filter parameter which can be used to tailor its output to include only parts of the schema which are of interest. What metadata is getting in your way? Why can't you just skip it?
If you'd prefer to use SPARQL, there's an RDF dump available that you could load in your own triple store and query with SPARQL.

freebase - topic description/articles

I'm trying to retrieve the topic description for some film ("/film/film") and film genres ("film/film_genre") in italian language.
I think the problem is the same in both cases, so I post the MQL query that I'm trying to run for the film genre description:
Mql query
[{
"type": "/film/film_genre",
"name": "Film culto",
"/common/topic/article": [{
"id": null
}]
}]
Response
{
"result": [{
"type": "/film/film_genre",
"name": "Film culto",
"/common/topic/article": [{
"id": "/m/01q0d"
}]
}]
}
With the article ID received ("/m/01q0d"), I would use the "trans/wrap" service (http://api.freebase.com/api/trans/raw/m/01q0d). However, even though I use the query parameter "lang=it", the article is in English... :(
Any suggestions? I'm going crazy :D
Freebase contains non-English names, but it doesn't, for the most part, contain descriptions in anything other than English. You could use the Topic API and get the /common/topic/topic_equivalent_webpage for the Italian Wikipedia to fetch the article/description from there, but that's probably the closest you'll get.
https://www.googleapis.com/freebase/v1/topic/m/01q03
And, as Phil said, the api.freebase.com is going away in a matter of days, so you need to be using the new APIs.

Resources