Chapter 3 of the MQL reference (specifically section 3.2.6) talks about inverting queries to obtain the same data in a different structure, either to simplify the query or massage the data to return a structure that's similar to your own.
So I start with the following query:
https://api.freebase.com/api/service/mqlread?query={"query":{"type":"/automotive/model","name":"Ford Taurus","generations":[]}}
Readable version:
{
"type":"/automotive/model",
"name":"Ford Taurus",
"generations":[]
}
Results:
{
"code": "/api/status/ok",
"result": {
"generations": [
"First Generation Ford Taurus",
"Second Generation Ford Taurus",
"Fifth Generation Ford Taurus",
"Sixth Generation Ford Taurus",
"Fourth Generation Ford Taurus",
"Third Generation Ford Taurus"
],
"name": "Ford Taurus",
"type": "/automotive/model"
},
"status": "200 OK",
"transaction_id": "cache;cache04.p01.sjc1:8101;2013-04-25T22:05:58Z;0012"
}
But I want to make the query generation-centric, so I modify it like so:
https://api.freebase.com/api/service/mqlread?query={"query":[{"type":"/automotive/generation","model":"Ford Taurus","name":null}]}
Readable version:
[{
"type":"/automotive/generation",
"model":"Ford Taurus",
"name":null
}]
Results:
{
"code": "/api/status/ok",
"result": [
{
"model": "Ford Taurus",
"name": "First Generation Ford Taurus",
"type": "/automotive/generation"
},
{
"model": "Ford Taurus",
"name": "Third Generation Ford Taurus",
"type": "/automotive/generation"
}
],
"status": "200 OK",
"transaction_id": "cache;cache01.p01.sjc1:8101;2013-04-25T23:00:35Z;0010"
}
My inverted query only returns two generations! Please help me figure out why this is.
If you look at the Freebase schema page for Automobile Generation you'll see that the model
property has been deprecated and replaced by a models property. Making that change to your query:
[{
"type": "/automotive/generation",
"models": "Ford Taurus",
"name": null
}]
Gives you the expected result set:
[
{
"models": "Ford Taurus",
"name": "First Generation Ford Taurus",
"type": "/automotive/generation"
},
{
"models": "Ford Taurus",
"name": "Second Generation Ford Taurus",
"type": "/automotive/generation"
},
{
"models": "Ford Taurus",
"name": "Fifth Generation Ford Taurus",
"type": "/automotive/generation"
},
{
"models": "Ford Taurus",
"name": "Sixth Generation Ford Taurus",
"type": "/automotive/generation"
},
{
"models": "Ford Taurus",
"name": "Fourth Generation Ford Taurus",
"type": "/automotive/generation"
},
{
"models": "Ford Taurus",
"name": "Third Generation Ford Taurus",
"type": "/automotive/generation"
}
]