简体   繁体   English

在Freebase中如何使用OR运算符?

[英]How to use OR operator in Freebase?

Case: 案件:

So, I'm using the OR operator or ONE OF as to get people from any of 2 countries. 因此,我使用OR运算符或ONE OF作为2个国家中任何一个的人。 The query looks like: 查询如下:

[{
  "id":    null,
  "type":  "/people/person",
  "/people/person/nationality": {
    "name|=": [
      "Jordan",
      "Ottoman Empire"
    ]
  },
  "name":  null,
  "limit": 30
}]

The query works fine, but it won't work if you increase the limit to be 40 for example. 该查询工作正常,但是如果将限制增加到40例如,它将无法正常工作。 The error returned is "Unique query may have at most one result. Got 2". 返回的错误是“唯一查询最多可能有一个结果。得到2”。 This means that there exist a person for both nationalities "Jordan" and "Ottoman Empire". 这意味着存在一个同时存在“约旦”和“奥斯曼帝国”两个民族的人。

Question: 题:

It makes sense for a "ONE OF" operator, but not for "OR" operator. 对于“ ONE OF”运算符有意义,但对于“ OR”运算符没有意义。 Is there any operator in Freebase that can query "ANY OF" or true "OR" to cover these cases? Freebase中是否有任何运算符可以查询“ ANY OF”或真实的“ OR”来覆盖这些情况?

You're getting the error because you used object notation ({}) which expects a single result in a place where you're returning two results and would those need an array ([]). 之所以会出现错误,是因为您使用了对象符号({}),该符号在返回两个结果的地方需要一个结果,而这些结果需要一个数组([])。

Having said that, I think what you really need to do is hoist your |= operator up a level to /people/person/nationality . 话虽如此,我认为您真正需要做的是将|=操作员提升到/people/person/nationality的级别。 Note also that you need array notation even if just asking for nationality results for a person, because it's multi-valued (eg Sirhan Sirhan has both Jordan and Mandatory Palestine as his nationality). 还请注意,即使只是索要一个人的国籍结果,您也需要数组表示法,因为它是多值的(例如Sirhan Sirhan既有约旦又有巴勒斯坦的强制性国籍)。

Here's a query that will do what you want (although you should really use IDs for the countries rather than their English labels): 这是一个查询,可以满足您的要求(尽管您应该对国家/地区使用ID,而不要使用英语标签):

[{
  "id": null,
  "name": null,
  "nationality": [],
  "type": "/people/person",
  "nationality|=": [
    "Jordan",
    "Ottoman Empire"
  ]
}]

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

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