【问题标题】:How do I limit the number of results for a specific variable in a SPARQL query?如何限制 SPARQL 查询中特定变量的结果数?
【发布时间】:2012-02-12 11:37:15
【问题描述】:

假设我有一个像这样的 SPARQL 查询,寻找与焦点资源具有某些共享属性的资源,并获取有关焦点资源的其他一些语句:

CONSTRUCT {
  ?focal pred:icate ?shared .
  ?other pred:icate ?shared .
}
WHERE {
  ?focal pred:icate ?shared ;
         more:info ?etc ;
         a "foobar" .
  ?other pred:icate ?shared .
}
LIMIT 500

如果有超过 500 个其他资源,则 LIMIT 可能会排除 more:info 语句和对象。那么,有没有办法说“我最多只想要 500 个?other,还是我必须将这个查询分成多个部分?

【问题讨论】:

    标签: query-optimization sparql


    【解决方案1】:

    您可以在子查询中使用LIMIT,例如:

    CONSTRUCT {
      ?focal pred:icate ?shared .
      ?other pred:icate ?shared .
    }
    WHERE {
        ?focal pred:icate ?shared ;
               more:info ?etc ;
               a "foobar" .
        { 
          SELECT ?shared {
            ?other pred:icate ?shared .
          }
          LIMIT 500
        }
    }
    

    【讨论】:

      【解决方案2】:

      http://www.w3.org/TR/2012/WD-sparql11-query-20120105/#modResultLimit

      LIMIT 子句为解决方案的数量设置了上限 回来。如果实际解决方案的数量,在应用 OFFSET 之后, 大于极限,则至多为极限解数 将被退回。

      您只能限制查询的解决方案数量,而不是其中的特定子集。您可以使用带有LIMIT 子句的子查询:http://www.w3.org/TR/sparql-features/#Subqueries

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-10
        • 2022-11-04
        • 1970-01-01
        • 2014-04-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多