Freebase retrieve not edited data - freebase

In addition to this question:link i'm asking if i can retrieve data like the text or even geolocation from topics that seems that they have not any info been entered(but there is text description from wikipedia)

So, the problem is that when you run the following query you don't get any results:
[{
"name": "River Thames",
"type": "/location/location",
"geolocation": [{
"latitude": null,
"longitude": null
}],
"/common/topic/article": [{
"text": {
"maxlength": 16384,
"chars": null
}
}]
}]​
Try it out
This is because Freebase doesn't have geocoordinates (yet) for a topic called "River Thames". In other words, there are no combination of facts in Freebase that will match this query structure exactly so it returns nothing. It does however have coordinates for the mouth of the river so you will get results for this similar query:
[{
"name": "River Thames",
"type": "/location/location",
"/geography/river/mouth_long_lat": [{
"latitude": null,
"longitude": null
}],
"/common/topic/article": [{
"text": {
"maxlength": 16384,
"chars": null
}
}]
}]​
Try it out
But what should you do if you don't know beforehand whether the data that you're looking for is completely filled out in Freebase yet?
You can mark certain parts of a query as being "optional" which means that they should be returned if the data is present but that the query should still return results even if that data isn't present. So for your original query that would look like this:
[{
"name": "River Thames",
"type": "/location/location",
"geolocation": [{
"latitude": null,
"longitude": null,
"optional": true
}],
"/common/topic/article": [{
"text": {
"maxlength": 16384,
"chars": null
}
}]
}]​
Try it out
Now you should get results with the text of the article present but the geolocation returned as an empty array.
One more thing I should point out is that you should be aware that the query you've written is asking for a list of ALL topics in Freebase with the name "River Thames". Right now, that query only returns one result but in the future, when more data is added to Freebase, it may return multiple results. If you're really only interested in THIS River Thames, you should query it using its unique MID like this:
{
"id": "/m/0d2kt"
"name": null,
"type": "/location/location",
"geolocation": [{
"latitude": null,
"longitude": null,
"optional": true
}],
"/common/topic/article": [{
"text": {
"maxlength": 16384,
"chars": null
}
}]
}​
Try it out

Related

Get one of many values from freebase?

Suppose I am trying to get the wikipage title of all freebase entities with type "/people/person"
[{
"type": "/people/person",
"mid": null,
"key": [{
"namespace": "/wikipedia/en",
"value": null
}]
}]
This returns me the following
"result": [
{
"type": "/people/person",
"key": [
{
"value": "Ann_Copland",
"namespace": "/wikipedia/en"
},
{
"value": "Jack_Abramof",
"namespace": "/wikipedia/en"
},
{
"value": "Jack_Abramoff",
"namespace": "/wikipedia/en"
},
....
Here Ann_Copland, Jack_Abramof, Jack_Abramoff all redirect to the same wikipedia page.
I only want one of the titles (Ann_Copland, Jack_Abramof, Jack_Abramoff ...) from the freebase query. Of course, I can query as above, and ignore the extra titles, but is there a smarter way of specifying the number of results that I expect?
I am not sure about this, but it seems like the following is returning unique pages:
https://www.googleapis.com/freebase/v1/mqlread?query=[{"name":[],"type":"/people/person"}]
To get unique value from your query add "limit":
https://www.googleapis.com/freebase/v1/mqlread?query=[{
"type": "/people/person",
"mid": null,
"key": [{
"limit": 1,
"namespace": "/wikipedia/en",
"value": null
}]
}]

Freebase combined query empty result set

I am trying to query freebase to get all the award winning movies that a person directed or acted in. If I run this with Steven Spielberg (who has both directed AND acted in award winning movies), it works fine:
[{
"/type/object/mid": "/m/06pj8",
"/film/director/film": [{
"type": "/award/award_winning_work",
"name": null
}],
"/film/actor/film": [{
"film": [{
"type": "/award/award_winning_work",
"name": null
}]
}]
}]
But the same query with Matt Damon (/m/0169dl) (who has not directed award winning movies but acts in those movies) returns nothing. I would expect to return all the movies Matt Damon acted in, in this case.
thanks
You can't do this in a single query without a little bit of post-processing, but adding optional:true to the subqueries will get you close
[{
"/type/object/mid": "/m/06pj8",
"/film/director/film": [{
"type": "/award/award_winning_work",
"name": null,
"optional": true
}],
"/film/actor/film": [{
"film": [{
"type": "/award/award_winning_work",
"name": null,
"optional": true
}]
}]
}]

What would the freebase MQL query for this?

I want to find the ceo of IBM. What would be the MQL query for this?
The MQL for this search looks like the following.
This particular instance may be a tat more complicated than necessary because I got it initially produced from a Freebase interactive search and then simply added/improved the filters manually.
I verified it with various company names with relative success, i.e. it works provided that the underlying data is properly codified in Freebase (some companies are missing, for some companies the leadership data is incomplete etc.)
There are a few tricks to this query:
the company name in u0 fitler needs to match precisely the company name as recorded in Freebase. You could use a contains predicate rather than an equal one, but that could introduce many irrelevant hits. For example you need to use "IBM", "Apple Inc.", "General Motors" rather than common alternatives to these names ("International Business Machines", "Apple", "GM"...")
the u1 filter, on the leadership role is expressed in a extensive One of predicate because unfortunately the nomenclature for these roles is relatively loose, with duplicates (e.g. could be CEO or Chief Executive Officer) and with the fact that the role of CEO is often coupled with other corporate roles such as Chairman [of the board] and/or President etc. I hand picked this list by first looking up (in Freebase) the instances of Leadership Roles which contained "CEO" or "Chief Executive".
the u2 filter expresses that the to date should be empty, to select only the person currently in office, as opposed to former CEOs (for which hopefully Freebase recorded the end date of their tenure).
Depending on your application, you may need to test that the query returns one and exactly one record, and adapt accordingly if it doesn't.
Freebase MQL editor is a convenient tool test and edit with this kind of queries.
[
{
"from": null,
"id": null,
"limit": 20,
"organization": {
"id": null,
"name": null,
"optional": true
},
"person": {
"id": null,
"name": null,
"optional": true
},
"role": {
"id": null,
"name": null,
"optional": true
},
"s0:type": [
{
"id": "/organization/leadership",
"link": [
{
"timestamp": [
{
"optional": true,
"type": "/type/datetime",
"value": null
}
],
"type": "/type/link"
}
],
"type": "/type/type"
}
],
"sort": "s0:type.link.timestamp.value",
"title": null,
"to": null,
"type": "/organization/leadership",
"u0:organization": [
{
"id": null,
"name": "IBM",
"type": "/organization/organization"
}
],
"u1:role": [
{
"id": null,
"name|=": ["Chief Executive Officer", "President and CEO", "Chairman and CEO", "Interim CEO", "Interim Chief Executive Officer", "Founder and CEO", "Chairman, President and CEO", "Managing Director and CEO", "Executive Vice President and Chief Operating Officer", "Co-Founder, Chairman and Chief Executive Officer"],
"type": "/organization/role"
}
],
"u2:to": [
{
"value": null,
"optional": "forbidden"
}
]
}
]​
Sample return (for "IBM", specifically)
{
"code": "/api/status/ok",
"result": [{
"from": "2012-01-01",
"id": "/m/09t7b08",
"organization": {
"id": "/en/ibm",
"name": "IBM"
},
"person": {
"id": "/en/virginia_m_rometty",
"name": "Virginia M. Rometty"
},
"role": {
"id": "/en/chairman_president_and_ceo",
"name": "Chairman, President and CEO"
},
"s0:type": [{
"id": "/organization/leadership",
"link": [{
"timestamp": [{
"type": "/type/datetime",
"value": "2010-01-23T08:02:57.0006Z"
}],
"type": "/type/link"
}],
"type": "/type/type"
}],
"title": "Chairman, President and CEO",
"to": null,
"type": "/organization/leadership",
"u0:organization": [{
"id": "/en/ibm",
"name": "IBM",
"type": "/organization/organization"
}],
"u1:role": [{
"id": "/en/chairman_president_and_ceo",
"type": "/organization/role"
}],
"u2:to": []
}

Freebase MQL query retrieving inconsistent results

When I run this query in the freebase query builder
[{
"/type/object/id": "/en/michael_jackson",
"/type/object/name": null,
"/type/object/type": "/music/artist",
"/music/artist/album": [{
"id": null,
"name": [],
"release_type!=": "Single",
"/music/album/primary_release": [{
"name": null,
"track_list": [{name:null}]
}]
}]
}];​
I get back the proper results, with album and track listing but if change the query to
[{
"/type/object/id": "/en/carly_rae_jepsen",
"/type/object/name": null,
"/type/object/type": "/music/artist",
"/music/artist/album": [{
"id": null,
"name": [],
"release_type!=": "Single",
"/music/album/primary_release": [{
"name": null,
"track_list": [{name:null}]
}]
}]
}];​
I dont get back anything. You can try both of these queries at http://www.freebase.com/queryeditor. Can somebody point out what am I doing wrong? Both of these are artist, so I should get back abum and track listing for Carly Rae Jepsen also.
Not all albums have a primary release recorded. Unless you really care about this, I'd loosen your constraints and use a query like this:
[{
"id": "/en/carly_rae_jepsen",
"name": null,
"type": "/music/artist",
"/music/artist/album": [{
"id": null,
"name": null,
"release_type!=": "Single",
"/music/album/releases": [{
"name": null,
"track_list": [{"name":null}]
}]
}]
}]​
Some other tweaks to the query:
the last "name" wasn't quoted
queries aren't terminated by a semicolon
/type/object is the default and can be omitted, similarly with properties associated with the most recently specified type
name is a single valued property, so one uses null as opposed to []
If you want the primary release if available, but not have it constrain your query, you can use "optional":true. You could get even fancier by sorting all releases by release date and only taking the first one (on the assumption that that's got a good chance of being the primary release).
The resulting query would look like this:
[{
"id": "/en/carly_rae_jepsen",
"name": null,
"type": "/music/artist",
"album": [{
"id": null,
"name": [],
"release_type!=": "Single",
"primary_release": [{
"optional": true,
"name": null,
"track_list": [{
"name": null
}]
}],
"releases": [{
"name": null,
"track_list": [{
"name": null
}],
"release_date": null,
"sort": "release_date",
"limit": 1
}]
}]
}]​

Related information about location in freebase are always null?

I'm trying to query freebase to find information about a specific city.
I'm able to find the city that I'm looking for but I need to get the description content as well as a few pictures.
My current query is
[{
"name": "san francisco",
"id": null,
"type": "/location/citytown",
"/location/location/geolocation" : [
{
"latitude": null,
"longitude": null,
"latitude>" : 36,
"latitude<" : 38 }]
"/common/topic/article" : [{ "id" : null, "content": null }],
"/common/topic/image" : [{
"id" : null,
"optional" : true,
"limit" : 15
"image_caption" : []
}]
}]
Which returns
{
"code": "/api/status/ok",
"result": [{
"/common/topic/article": [{
"content": null,
"id": "/m/0d6l_"
}],
"/common/topic/image": [
{
"id": "/m/02929wx",
"image_caption": []
},
{
"id": "/m/04j74y4",
"image_caption": []
},
{
"id": "/m/04j74yh",
"image_caption": []
},
{
"id": "/m/04j74yw",
"image_caption": []
},
{
"id": "/m/04j74z6",
"image_caption": []
}
],
"/location/location/geolocation": [{
"latitude": 37.775,
"longitude": -122.4183
}],
"id": "/en/san_francisco",
"name": "San Francisco",
"type": "/location/citytown"
}],
"status": "200 OK",
"transaction_id": "cache;cache03.p01.sjc1:8101;2012-07-24T21:50:06Z;0029"
}
I can't get the content value and the captions to be set.
Am I missing something ?
Where did you find the "image_caption" property? If you switch it to "name" you should get the names of the images (which are used as captions in some UI contexts).
The text content isn't available from MQL, but you can get it from the BLOB service in the old API or the text API in the new APIs using the ID that is returned for the article. e.g. https://www.googleapis.com/freebase/v1/text/m/0d6l_
p.s. If you just want the primary image, you might consider using the Topic API which will return you the image, it's name, the text blurb, and a bunch of other info in a single call.
https://www.googleapis.com/freebase/v1/topic/wikipedia/en_id/49728
Using the Search API will give you more robust name matching as well as give you a score which will tell you how likely it is that the query is ambiguous (if you get multiple matches with scores close to each other).
https://www.googleapis.com/freebase/v1/search?query=%22san%20francisco%22&type=/location/citytown

Resources