Get one of many values from freebase? - 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
}]
}]

Related

GraphDb Indexing Policies

Consider the following json responses..
If you run the graph query g.V().hasLabel('customer'), the response is:
[
{
"id": "75b9bddc-4008-43d7-a24c-8b138735a36a",
"label": "customer",
"type": "vertex",
"properties": {
"partitionKey": [
{
"id": "75b9bddc-4008-43d7-a24c-8b138735a36a|partitionKey",
"value": 1
}
]
}
}
]
If you run the sql query select * from c where c.label = 'customer', the response is:
[
{
"label": "customer",
"partitionKey": 1,
"id": "75b9bddc-4008-43d7-a24c-8b138735a36a",
"_rid": "0osWAOso6VYBAAAAAAAAAA==",
"_self": "dbs/0osWAA==/colls/0osWAOso6VY=/docs/0osWAOso6VYBAAAAAAAAAA==/",
"_etag": "\"2400985f-0000-0c00-0000-5e2066190000\"",
"_attachments": "attachments/",
"_ts": 1579181593
}
]
Q: With this difference in structure around the partitionKey section, should this be referenced as /properties/partitionKey/*, or /partitionKey/? in the indexing policy?
Currently i have hedged by bets with...
{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [{
"path": "/properties/partitionKey/*"
},{
"path": "/partitionKey/?"
},{
"path": "/label/?"
}
],
"excludedPaths": [{
"path": "/*"
},{
"path": "/\"_etag\"/?"
}
]
}
TIA! 😁
This should be stored as "/partitionKey" in your index policy, not "/properties/partitionKey"
btw, another thing to point out here is it's generally better to only exclude paths you will never query on rather than have to include those you will. This way, if you add properties to your graph you won't have to rebuild the index to query on the new properties.

Controlling output on MQL query -- search by a field, but not output it

I am curious if I can control the results of a query so that it will not display the a particular field in the query. For instance...
query:
[{
"id": null,
"name": null,
"type": "/people/person"
}]
result:
{
"result": [
{
"type": "/people/person",
"id": "/en/jack_abramoff",
"name": "Jack Abramoff"
},
{
"type": "/people/person",
"id": "/en/bob_ney",
"name": "Bob Ney"
},...
I have tried this...
[{
"id": null,
"name": null,
"type": [{
"id": "/people/person",
"limit": 0
}]
}]
Which gives me ...
{
"result": [
{
"type": [],
"id": "/en/jack_abramoff",
"name": "Jack Abramoff"
},
{
"type": [],
"id": "/en/bob_ney",
"name": "Bob Ney"
},...
I am wondering if there is a way to just get this
{
"result": [
{
"id": "/en/jack_abramoff",
"name": "Jack Abramoff"
},
{
"id": "/en/bob_ney",
"name": "Bob Ney"
},...
No, there is no way to do this. Why would you need to do this? Once you parse the JSON data in your application its very easy to just ignore any values that you don't need. The APIs support using gzip compression so you don't have to worry about the response size either. If you're really optimizing for speed you might consider switching to the Search API which looks like this:
https://www.googleapis.com/freebase/v1/search?filter=(all+type:/people/person)

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

Freebase retrieve not edited data

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

Resources