SPARQL-过滤所有仅包含条件的实例

发布于 2025-02-04 04:29:42 字数 1141 浏览 5 评论 0原文

我有具有类别的成分的食谱。

@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:planteex: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:meatex:ex:fish。如果任何ex:Meatex: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文