获取Freebase中每个菜单的菜单和详细信息列表?

时间:2013-09-29 03:06:03

标签: json node.js api rdf freebase

我尝试了这个查询来获取所有菜单实例的列表

[{
  "id": null,
  "name": null,
  "type": "/food/dish"
}]

但它只给了我第一页:

http://www.freebase.com/query?autorun=1&q=%5B%7B%22id%22:null,%22name%22:null,%22type%22:%22/food/dish%22%7D%5D

问题1:如何添加分页以获取所有2.5K左右的碟形实例?我试图添加“cursor:2”并且无效。


假设我有一个名字“披萨”,我尝试了这个查询来获取“披萨”的详细信息:

{
  "*": null,
  "name": "pizza",
  "type": "/food/dish"
}

但是这并没有给我这样的描述和图像http://www.freebase.com/m/0663v

问题2:如何获取所有信息,或者至少在上面的免费基页中获取描述和图片网址?

奖金:我试图通过Freebase Node.js在https://github.com/spencermountain/Freebase.js

做所有事情

2 个答案:

答案 0 :(得分:5)

我建议您将此分为2个问题,因此每个问题都有自己的主题,以后的访问者可以更轻松地进行搜索。

那说:

问题1

您可以通过向查询添加limit:来增加每页获得的结果数量。无论如何,您将不得不使用分页。要使用分页,您需要将cursor参数添加到mqlread HTTP请求中。同样:cursor 不是 MQL查询本身的一部分,而是提交它的HTTP信封。

对于第一个查询,发出一个空cursor,对于后续查询,请使用mqlread返回给您的cursor值。

请注意,所有这些都需要使用API​​完成,而不是直接使用freebase,因此URL必须是:

https://www.googleapis.com/freebase/v1/mqlread?cursor=&query=[{"id":null,"name":null,"type":"/food/dish","limit":5}]

另请注意,如果您计划执行除测试以外的任何操作,则需要从Google获取密钥。

最后,请注意Freebase中的某些字符串是“freebase-encoded”,请阅读有关如何在结果中解码它们的信息。

问题2

如果您只想要成分名称,只需在查询中添加"/dining/cuisine/ingredients": []即可。请注意,许多菜肴没有配料,但披萨确实:

{
  "id": "/m/0663v",
  "name": null,
  "type": "/food/dish",
  "/dining/cuisine/ingredients": []
}

获取图片意味着在查询中添加"/common/topic/image": [{}],并为每张图片使用返回的id

通过将id添加到https://usercontent.googleapis.com/freebase/v1/image/来完成从给定图片id获取图片网址。

修改

汤姆正确地注意到我忘记了图像描述。每个图像的描述将在返回的name:数组中的/common/topic/image下提供。例如,对于查询

[{
  "id": "/en/minestrone",
  "/common/topic/image": [{
    "id": null,
    "name": null
  }]
}]

您将获得以下图片及其说明:

{
  "result": [{
    "id": "/en/minestrone",
    "/common/topic/image": [
      {
        "id": "/wikipedia/images/commons_id/1492185",
        "name": "MinestroneSoup"
      },
      {
        "id": "/wikipedia/images/commons_id/12565901",
        "name": "Homemade minestrone"
      }
    ]
  }]
}

您的最终MQL是:

[{
  "id": null,
  "name": null,
  "type": "/food/dish",
  "/common/topic/image": [{
    "id": null,
    "name": null
  }],
  "/dining/cuisine/ingredients": []
}]

...并且HTTP信封将包含cursor的密钥和值。

答案 1 :(得分:1)

请参阅Nitzan对问题1答案的回答。

对于您的第二个问题,获取说明和图片的最简单方法是使用Topic API,例如https://www.googleapis.com/freebase/v1/topic/m/0663v