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

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)

Related

OpenRefine reconciliation service not working - mutliple vs single queries

I have been using OpenRefine 2.6 Beta 1 w/o problems since its release, and later, with the reconciliation service at:
http://reconcile.freebaseapps.com/reconcile
However, in the past fee days, I have not been able to use it all. If I go to the URL:
http://reconcile.freebaseapps.com/
and type the multiple query:
{
"query": "Ford",
"type": "/people/person",
"properties": [
{
"pid": "/people/person/place_of_birth",
"v": "Detroit"
}
]
}
I obtain:
{
"result": [
{
"id": "/m/0j8pb6y",
"name": "Ford",
"type": [
{
"id": "/people/person",
"name": "Person"
},
{
"id": "/common/topic",
"name": "Topic"
},
{
"id": "/geography/mountaineer",
"name": "Mountaineer"
}
],
"notable": [],
"score": 1.1546246,
"match": false
},
{
"id": "/m/01vd3gv",
"name": "Ford",
"type": [
{
"id": "/common/topic",
"name": "Topic"
},
{
"id": "/music/artist",
"name": "Musical Artist"
}
],
"notable": [],
"score": 1.0330245999999998,
"match": false
},
{
"id": "/m/0cmdhzt",
"name": "James Meredith",
"type": [
{
"id": "/common/topic",
"name": "Topic"
},
{
"id": "/people/person",
"name": "Person"
},
{
"id": "/military/military_person",
"name": "Military Person"
},
{
"id": "/people/deceased_person",
"name": "Deceased Person"
}
],
"notable": [],
"score": 0.0681692,
"match": false
}
],
"duration": 369
}
But if I try a simple query:
{
"query": "Ford"
}
I get:
Status: error Error:undefined
Any insights into what's happening with the reconciliation service? Is there any other service I could use to replace freebaseapps.com?
Thanks
Try this in Queries Parameter at http://reconcile.freebaseapps.com/
{
"q0": {
"query": "Ford"
}
}
For some reason, single queries are not accepted in Query Parameter but in Queries Parameter in the format above. I have not tested this in OpenRefine, so you might have to modify it.
I don't know for certain about the date, but Freebase was announced earlier this year as being shutdown by Jun 30, 2015, for some services. Maybe service is intermittent until full shutdown? Sorry, this answer probably doesn't help much.

How to create compound documents?

I'm thinking of using the JSONAPI standard for the design of our API. One thing this API must be able to do, is accept a compound document (several layers deep) and create it. The root object owns all descendants ('to-many' relationships) which the server knows nothing about at that point, so it's not possible for the client to provide an id.
Is this supported by the specification or does the client have to issue http requests for every object in the document in order?
from http://jsonapi.org/format/#document-compound-documents
Compound documents require "full linkage", meaning that every included
resource MUST be identified by at least one resource identifier object
in the same document. These resource identifier objects could either
be primary data or represent resource linkage contained within primary
or included resources. The only exception to the full linkage
requirement is when relationship fields that would otherwise contain
linkage data are excluded via sparse fieldsets.
{
"data": [{
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!"
},
"links": {
"self": "http://example.com/articles/1"
},
"relationships": {
"author": {
"links": {
"self": "http://example.com/articles/1/relationships/author",
"related": "http://example.com/articles/1/author"
},
"data": { "type": "people", "id": "9" }
},
"comments": {
"links": {
"self": "http://example.com/articles/1/relationships/comments",
"related": "http://example.com/articles/1/comments"
},
"data": [
{ "type": "comments", "id": "5" },
{ "type": "comments", "id": "12" }
]
}
}
}],
"included": [{
"type": "people",
"id": "9",
"attributes": {
"first-name": "Dan",
"last-name": "Gebhardt",
"twitter": "dgeb"
},
"links": {
"self": "http://example.com/people/9"
}
}, {
"type": "comments",
"id": "5",
"attributes": {
"body": "First!"
},
"links": {
"self": "http://example.com/comments/5"
}
}, {
"type": "comments",
"id": "12",
"attributes": {
"body": "I like XML better"
},
"links": {
"self": "http://example.com/comments/12"
}
}]
}

Empty sparse fieldset in JSON API

I have a resource (e.g. posts) which has a to-many relationship to other resources (e.g. comments). I do not need any fields of the related resource but their self-links (to fetch them asynchronously on demand). The response should look something like this:
{
"links": {
"self": "http://example.com/posts/1?xxx",
},
"data": [{
"type": "posts",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!"
},
"relationships": {
"comments": {
"links": {
"self": "http://example.com/posts/1/relationships/comments",
"related": "http://example.com/posts/1/comments"
},
"data": [
{ "type": "comments", "id": "5" },
{ "type": "comments", "id": "12" }
]
}
},
"links": {
"self": "http://example.com/posts/1"
}
}],
"included": [{
"type": "comments",
"id": "5",
"links": {
"self": "http://example.com/comments/5"
}
}, {
"type": "comments",
"id": "12",
"links": {
"self": "http://example.com/comments/12"
}
}]
}
My question is how should the URL for the request look like?
My idea would be to include the comments and then use an empty sparse fieldset to avoid getting any comment fields but just the self link (+id, type).
Hence, it should look something like http://example.com/posts/1?include=comments&fields[comments]=[].
So I need something like an empty sparse fieldset.
The JSON API specification does not say much about sparse fieldsets (http://jsonapi.org/format/#fetching-sparse-fieldsets) and their relation to links.
The JSON API was able to answer my question.
In short, the correct way to specify an empty sparse fieldset would be:
http://example.com/posts/1?include=comments&fields[comments]=
There's a discussion going on about whether to include the links to individual relationship items in the relationship object:
{
"links": {
"self": "http://example.com/posts/1",
},
"data": [{
"type": "posts",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!"
},
"relationships": {
"comments": {
"links": {
"self": "http://example.com/posts/1/relationships/comments",
"related": "http://example.com/posts/1/comments",
"item": [ "http://example.com/comments/5", "http://example.com/comments/12" ]
},
"data": [{
"type": "comments",
"id": "5",
"links": {
"about": "http://example.com/comments/5"
}
}, {
"type": "comments",
"id": "12",
"links": {
"about": "http://example.com/comments/12"
}
}]
}
},
"links": {
"self": "http://example.com/posts/1"
}
}]
}

Finding only exact matches using Freebase api

I would like to use the Freebase Api to determine if a certain thing refers to an entity (e.g. person, tv show, ...). For instance "how i met your mother" refers to a TV show, "lana del rey" is a singer. However if something is not an entity, I would like to know that as well.
Unfortunately the Freebase search api gives me quite a few false positives for things that are not clear entities, even with the parameter exact=true and prefix=false:
For instance: https://www.googleapis.com/freebase/v1/search?query=girl&exact=true
[
{
"mid": "/m/0ytdbkr",
"name": "Naked girl",
"notable": {
"name": "Film character",
"id": "/film/film_character"
},
"lang": "en",
"score": 5.222793
},
{
"mid": "/m/0y4k26c",
"name": "Sexy girl",
"notable": {
"name": "Film character",
"id": "/film/film_character"
},
"lang": "en",
"score": 4.754522
},
{
"mid": "/m/0yg73tt",
"name": "Call girl",
"notable": {
"name": "Film character",
"id": "/film/film_character"
},
"lang": "en",
"score": 4.567947
},
{
"mid": "/m/0w1sb51",
"name": "Gorgeous girl",
"notable": {
"name": "Film character",
"id": "/film/film_character"
},
"lang": "en",
"score": 4.526981
},
{
"mid": "/m/03p0tvg",
"id": "/user/girl",
"name": "girl",
"lang": "en",
"score": 4.465735
},
{
"mid": "/m/05p197",
"id": "/en/bad_girl_movies",
"name": "Bad girl movies",
"notable": {
"name": "Film genre",
"id": "/film/film_genre"
},
"lang": "en",
"score": 4.464571
},
....
]
}
What's an "exact" match in this context?
If you simply want an exact name & type match, you can get that using the MQLRead API instead of the Freebase Search API. If you're looking for something different, you need to be more specific about what you seek...

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
}]
}]

Resources