I’m using freebase python to access the freebase api. I have the following query I would like to execute:
query = [{
"id": None,
"name" : [],
"type" : "/people/person",
"/common/topic/image":[{}],
"limit" : 10,
"type" : []
}]
results = freebase.mqlread(query)
Basically I want to have some instances from people and also get what other types are they part of. But when I try to run this I get errors:
{u'id': u'/user/root', u'type': [u'/type/user'], u'/common/topic/image': [{u'type': [u'/type/content', u'/common/image'], u'id': u'/m/05kdqcb', u'name': None}], u'name': [u'Freebase Staff']}
{u'id': u'/', u'type': [u'/type/namespace'], u'/common/topic/image': [], u'name': []}
{u'id': u'/type/namespace/keys', u'type': [u'/type/property'], u'/common/topic/image': [], u'name': [u'keys']}
{u'id': u'/boot', u'type': [u'/type/namespace'], u'/common/topic/image': [], u'name': []}
{u'id': u'/boot/root_permission', u'type': [u'/type/permission'], u'/common/topic/image': [], u'name': [u'Root Permission']}
{u'id': u'/type/object/permission', u'type': [u'/type/property'], u'/common/topic/image': [], u'name': [u'permission']}
{u'id': u'/type/object/type', u'type': [u'/type/property'], u'/common/topic/image': [], u'name': [u'type']}
{u'id': u'/type', u'type': [u'/type/namespace', u'/type/domain'], u'/common/topic/image': [], u'name': [u'Metaweb System Types']}
{u'id': u'/type/type', u'type': [u'/type/type'], u'/common/topic/image': [], u'name': [u'Type']}
{u'id': u'/type/namespace', u'type': [u'/type/type'], u'/common/topic/image': [], u'name': [u'Namespace']}
However it works fine when I use the same query in the Freebase query editor. See the query run here.
Any ideas?
Thanks!
Your query has two clauses called “type” which is not valid JSON and therefore not a valid MQL query. Most JSON parsers will just overwrite the first “type” clause with the second one which means that you actually end up running the following query:
Try it out
You should now see the same results as you posted above. This isn’t an error, its just the results to a less interesting query.
To get around the restriction of only having one clause for any given property, MQL allows arbitrary prefixes to be added to a property like “foo:type” or “bar:type”. The query editor will actually automatically add these in for you if you forget to add them yourself (but when you use the API you have to remember to do it yourself). So the query that you linked to shows up like this in the query editor: