SPARQL-过滤所有仅包含条件的实例
我有具有类别的成分的食谱。
@prefix schema: <http://schema.org/> .
@prefix ex: <http://example.org> .
ex:recipe1 a schema:Recipe ;
schema:recipeIngredient ex:ingredient1 , ex:ingredient3 .
ex:recipe2 a schema:Recipe ;
schema:recipeIngredient ex:ingredient1, ex:ingredient2 .
ex:ingredient1 ex:category ex:plant .
ex:ingredient2 ex:category ex:spice .
ex:ingredient3 ex:category ex:meat .
ex:ingredient4 ex:category ex:fish .
我想过滤所有仅包含类别中的成分的配方ex:plante
或ex:spice
。我尝试过:
SELECT ?recipes
WHERE {
?recipes a schema:Recipe;
schema:recipeIngredient ?ingredient.
?ingredient ex:category ?category.
FILTER(?category NOT IN (ex:meat && ex:fish))
}
这是返回两个食谱,我猜是因为ex:repipe1
还包括ex:plant
。但是,我所需的输出仅是ex:recipe2
,因为它不包含任何ex:meat
或ex:ex:fish
。如果任何ex:Meat
或ex:fish
包含在食谱中,我希望将其排除在结果集中。
I have recipes with ingredients that have a category.
@prefix schema: <http://schema.org/> .
@prefix ex: <http://example.org> .
ex:recipe1 a schema:Recipe ;
schema:recipeIngredient ex:ingredient1 , ex:ingredient3 .
ex:recipe2 a schema:Recipe ;
schema:recipeIngredient ex:ingredient1, ex:ingredient2 .
ex:ingredient1 ex:category ex:plant .
ex:ingredient2 ex:category ex:spice .
ex:ingredient3 ex:category ex:meat .
ex:ingredient4 ex:category ex:fish .
I want to filter all recipes that only contain ingredients from the category ex:plants
or ex:spice
. I tried:
SELECT ?recipes
WHERE {
?recipes a schema:Recipe;
schema:recipeIngredient ?ingredient.
?ingredient ex:category ?category.
FILTER(?category NOT IN (ex:meat && ex:fish))
}
This returns both recipes, I guess because ex:recipe1
also includes a ex:plant
. However, my desired output is only ex:recipe2
because it does not contain any ex:meat
or ex:fish
. If any ex:meat
or ex:fish
is included in the recipes, I want it to be excluded from the result set.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论