SPARQL 查询限制答案

SPARQL query restric answer

我有以下查询:

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 ?r (count(distinct ?Ingrediente) as ?oi)  {
?r rec:Ingrediente ?Ingrediente. 
     filter not exists {
        ?r rec:Ingrediente ?other_ingredient 
        filter( ?other_ingredient not in ( rec:Aceite, rec:Cebolla ) )  
     }
   }
GROUP BY ?r 
order by (count(distinct ?Ingrediente))

我明白了:

 ?r         ?oi
 Recipe1    1
 Recipe2    2

我想得到这样的东西:

 ?r         ?oi     ?PreparationMode        ?IngredientList
 Recipe1    1       First, you have to..    ing1, ing2, ing3... 
 Recipe2    2       First, you have to..    ing1, ing2, ing3... 

我试过这样做:

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 ?r (count(distinct ?Ingrediente) as ?oi) ?mo  ?sa{
?r rec:Ingrediente ?Ingrediente. 
?m rdf:type rec:ModoPreparacion.
?m rdfs:label ?mo.
?s rdf:type rec:ListaIngredientes.
?s rdfs:label ?sa.
filter not exists {
  ?r rec:Ingrediente ?other_ingredient 
  filter( ?other_ingredient not in ( rec:Aceite, rec:Cebolla ) )    
   }
}
GROUP BY ?r ?mo ?sa
order by (count(distinct ?Ingrediente))

但是我多次收到食谱名称,但我不知道如何解决。任何想法?谢谢!!!

这是 DDBB 结构:

每个食谱都有配料和准备方式:

每个准备模式都有一个带有描述的标签:

并且每份成分表都有一个带有其他描述的标签:

还有门生 ddbb:

http://webprotege.stanford.edu/#Edit:projectId=bb11a09e-29f5-47c5-b2f9-a81c3a88aa9d5

变量 ?r 和 ?m 之间没有联系:

?r rec:Ingrediente ?Ingrediente. 
?m rdf:type rec:ModoPreparacion.

这表示 "find (a recipe) ?r with an ingredient ?Ingrediente and an ?m with type rec:ModoPreparacion." 这意味着您可以找到所有可能的组合。与以下数据比较:

:John a :Person; :hasAge 30 .
:Bill a :Person; :hasAge 35 .

如果你写这样的查询

select ?person ?age {
  ?person a :Person .
  ?y :hasAge ?age .
}

您将在结果中得到四行:

John 30
Bill 30
John 35
Bill 35