我是 MQL 的绝对初学者,试图通过ken-rb以这种方式访问 Freebase :
[1] pry(main)> res = Ken.get("/en/allium_neapolitanum")
=> #<Resource id="/en/allium_neapolitanum" name="Allium neapolitanum">
我注意到通过 freebase API 提交的查询:
{"guid":null,"name":null,"ken:type":[
{"id":null,"name":null,"properties":[
{"id":null,
"name":null,
"expected_type":null,
"unique":null,
"reverse_property":null,
"master_property":null}]}],
"/type/reflect/any_master":[
{"id":null,
"link":null,
"name":null,
"optional":true,
"limit":999999}],
"/type/reflect/any_reverse":[
{"id":null,
"link":null,
"name":null,
"optional":true,
"limit":999999}],
"/type/reflect/any_value":[
{"link":null,
"value":null,
"optional":true,
"limit":999999}],
"id":"/en/allium_neapolitanum"}
在查询编辑器中摆弄这个 MQL,我找到了一种方法来简单地获取我的资源的常用名称列表:
[2]pry(#<Ken::Resource>):2> data["/type/reflect/any_value"].map { |h| h }
=> [{"link"=>"/type/object/name", "value"=>"Allium neapolitanum"},
{"link"=>"/type/object/name", "value"=>"שום משולש"},
{"link"=>"/type/object/name", "value"=>"Ail blanc"},
{"link"=>"/biology/organism_classification/scientific_name",
"value"=>"Allium neapolitanum"},
{"link"=>"/type/object/name", "value"=>"Neapolitanischer Lauch"}]
[3] pry(#<Ken::Resource>):2> names = data["/type/reflect/any_value"].select { |h| h["link"]=="/type/object/name"}
=> [{"link"=>"/type/object/name", "value"=>"Allium neapolitanum"},
{"link"=>"/type/object/name", "value"=>"שום משולש"},
{"link"=>"/type/object/name", "value"=>"Ail blanc"},
{"link"=>"/type/object/name", "value"=>"Neapolitanischer Lauch"}]
[4] pry(#<Ken::Resource>):2> names.map { |name| name["value"] }
=> ["Allium neapolitanum", "שום משולש", "Ail blanc", "Neapolitanischer Lauch"]
问题是:我需要知道哪种语言(我的意思是一个属性,例如:“lang: '/lang/fr'”)与每个通用名称相关。
有机会,使用 Ken 或通过更改 MQL 查询/提交其他查询/等,还有每个“/type/object/name”的语言是什么?
[编辑]
我找到了一种可能的解决方案,但是,我的目标是让数据直接修改由ken-rb发起的原始查询(..复制到问题的顶部)
MQL 可以是:
[{
"name": [{
"lang": null,
"value": null
}]
"id": "/en/allium_neapolitanum"
}]
给出这个结果
"result": [{
"id": "/en/allium_neapolitanum",
"name": [
{
"lang": "/lang/en",
"value": "Allium neapolitanum"
},
{
"lang": "/lang/he",
"value": "שום משולש"
},
{
"lang": "/lang/fr",
"value": "Ail blanc"
},
{
"lang": "/lang/de",
"value": "Neapolitanischer Lauch"
}
]
}]