简体   繁体   English

如何在freebase搜索小部件中选择类别?

[英]how to select category as well in freebase search widget?

i was using Freebase Search Widget for my project, using it i can select the word from the suggestion list in my input box, but how to get the category as well in another text box ? 我正在为我的项目使用Freebase Search Widget,使用它我可以从输入框中的建议列表中选择单词,但是如何在另一个文本框中获得类别?

Example: http://suggest-examples.freebaseapps.com/ 示例: http//suggest-examples.freebaseapps.com/

If i type: James Cameron, it will be selected in the text box, but i also want the category to be selected in another text box ? 如果我输入:James Cameron,它将在文本框中选择,但是我也希望在另一个文本框中选择类别?

Code: 码:

$(function() {
  $("#myinput").suggest({
    key: "YOUR-API-KEY-GOES-HERE",
    filter:'(all type:/film/director)'
  });
});

The Freebase Search widget uses the Freebase Search API to suggest entities. Freebase Search小部件使用Freebase Search API来建议实体。 So When you type "james cameron" into the input field, you're sending the following Search API request: 因此,当您在输入字段中输入“ james cameron”时,您将发送以下Search API请求:

https://www.googleapis.com/freebase/v1/search?query=james+cameron&exact=false&prefixed=true

You can see in the responses from that API call that it passes back the name, ID, a ranking and what the entity is notable for: 您可以从该API调用的响应中看到它传回了名称,ID,排名以及该实体值得注意的地方:

{
  "mid": "/m/03_gd",
  "id": "/en/james_cameron",
  "name": "James Cameron",
  "notable": {
    "name": "Film Director",
    "id": "/m/02jknp"
  },
  "lang": "en",
  "score": 629.205872
},...

All of this data is accessible from the jQuery callback in the Search widget like this: 所有这些数据都可以通过Search小部件中的jQuery回调进行访问,如下所示:

$(function() {
  $("#myinput").suggest({
    key: "YOUR-API-KEY-GOES-HERE",
    filter:'(all type:/film/director)'
  }).bind("fb-select", function(e, data) {
    alert(data.name + ", " + data.id + " (" + data.notable.name + ")");
  });
});

In this case, James Cameron ( /m/03_gd ) is notable for being a film director ( /m/02jknp ). 在这种情况下,詹姆斯·卡梅隆( / m / 03_gd )以电影导演( / m / 02jknp )着称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM