Chapter 3 of the MQL reference(特别是第3.2.6节)讨论了反转查询以获得不同结构中的相同数据,以简化查询或按摩数据以返回与您类似的结构自己的。
所以我从以下查询开始:
https://api.freebase.com/api/service/mqlread?query={"query":{"type":"/automotive/model","name":"Ford Taurus","generations":[]}}
可读版本:
{
"type":"/automotive/model",
"name":"Ford Taurus",
"generations":[]
}
结果:
{
"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"
}
但是我想让查询以生成为中心,所以我这样修改它:
https://api.freebase.com/api/service/mqlread?query={"query":[{"type":"/automotive/generation","model":"Ford Taurus","name":null}]}
可读版本:
[{
"type":"/automotive/generation",
"model":"Ford Taurus",
"name":null
}]
结果:
{
"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"
}
我的倒置查询只返回两代!请帮我弄清楚这是为什么。
答案 0 :(得分:1)
如果您查看Automobile Generation的Freebase架构页面,您会看到model
属性已被弃用,并被 models 属性取代。对您的查询进行更改:
[{
"type": "/automotive/generation",
"models": "Ford Taurus",
"name": null
}]
为您提供预期的结果集:
[
{
"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"
}
]