Rdf 避免指定显式枚举资源的数量?

Rdf 避免指定显式枚举资源的数量?,rdf,sparql,having,rdfs,Rdf,Sparql,Having,Rdfs,我的SPARQL查询有问题。我想要的食谱包含的成分少于我提供的数量。以下是查询: PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX owl: <http://www.w3.org/2002/07/owl#> PREFIX rdfs: <http://www.w3

我的SPARQL查询有问题。我想要的食谱包含的成分少于我提供的数量。以下是查询:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rec:<http://www.receta.org#>
select ?recipe  (count(distinct ?Ingrediente) as ?oi) {
  ?recipe rec:Ingrediente ?Ingrediente
  filter not exists {
    ?recipe rec:Ingrediente ?other_ingredient
    filter( ?other_ingredient not in (rec:Cebolla,rec:Tomate, rec:Aceite, rec:Sal) )
  }}
group by ?recipe
having(  (count(distinct ?Ingrediente)) < 4)
order by (count(distinct ?Ingrediente))
前缀rdf:
前缀rdf:
前缀owl:
前缀rdfs:
前缀xsd:
前缀rec:
选择?配方(将(不同的?Ingredite)计数为?oi){
?配方记录:Ingrediente?Ingrediente
筛选器不存在{
?配方记录:Ingrediente?其他成分
过滤器(?其他成分不在(rec:Cebolla,rec:Tomate,rec:Aceite,rec:Sal))
}}
按配方分组
具有((计数(不相同的?不一致的)小于4)
订货人(计数(不同?不一致)
这里有一个例子。假设我有这些食谱:

  • prueba3:cebolla
  • 普鲁巴:塞博拉,亚齐特人
  • 普鲁巴2号:切博拉、埃塞特、番茄
  • prueba4:cebolla、tomate、aceite、sal
然后我想打印:

  • prueba3:cebolla
  • 普鲁巴:塞博拉,亚齐特人
  • 普鲁巴2号:切博拉、埃塞特、番茄
我不想打印prueba4,因为它的成分完全相同

查询的主要问题是“having”行:
having((count(distinct?Ingrediente))<4)
。在这种情况下,这是可行的,但我不想放4,我想用一种通用的方式,所以我不必每次添加更多的成分时都改变这个数字


那我该怎么改变这条线呢?谢谢

在SELECT绑定之后执行'having'子句,因此可以有如下内容:

PREFIX ...
select ?recipe  (count(distinct ?Ingrediente) as ?oi) (4 AS ?count)
WHERE {
   ?recipe rec:Ingrediente ?Ingrediente
   filter not exists {
   ?recipe rec:Ingrediente ?other_ingredient
   filter( ?other_ingredient not in (rec:Cebolla,rec:Tomate, rec:Aceite, rec:Sal) )
 }}
group by ?recipe
having(?oi < ?count)
order by ?oi
前缀。。。
选择配方(计数(不同的Ingrediente)作为oi)(4作为计数)
在哪里{
?配方记录:Ingrediente?Ingrediente
筛选器不存在{
?配方记录:Ingrediente?其他成分
过滤器(?其他成分不在(rec:Cebolla,rec:Tomate,rec:Aceite,rec:Sal))
}}
按配方分组
有(?oi<?计数)
订购人?oi

…where?count可以根据从数据中查询的值或某些三重匹配的计数来计算。

根据SPARQL.org的查询验证程序,您的查询是合法的SPARQL,但问题标题在“having”行上显示查询错误。这个问题听起来好像你只是想避免在查询中输入一些东西。查询中确实有错误吗?我写信给你之前的问题,这实际上是我写这篇文章时想知道的事情之一。当时我试图想出一个办法,但没有想到一个好的解决办法。当然,如果查询是按程序构造的,那么注入这些值应该不会太难。是的,你是对的。这不是一个错误。很抱歉我只是想让它像我说的那样“全球化”。我不想每次改变配料量时都改变这个数字。关键是我想从网络上获取这些值,这样数字就会改变。