我有以下查询:
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结构:
每个食谱都有成分和准备模式:
每种准备模式都有一个带有描述的标签:
每个成分列表都有一个带有其他描述的标签:
这里也是protégéddbb:
http://webprotege.stanford.edu/#Edit:projectId=bb11a09e-29f5-47c5-b2f9-a81c3a88aa9d 5
答案 0 :(得分:3)
变量之间没有联系?r和?m:
?r rec:Ingrediente ?Ingrediente.
?m rdf:type rec:ModoPreparacion.
这说&#34;找到(配方)?r含有成分?Ingrediente和?mm类型rec:ModoPreparacion。&#34;这意味着你找到了所有可能的组合。与以下数据比较:
: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