SPARQL查询RECIPE选择

时间:2012-09-08 12:53:03

标签: filter sparql

好吧,让我们说我需要提取所有含有2/3成分的食谱。 配方表示为链接数据,这是使用的本体http://linkedrecipes.org/schema。 我知道如何找到咖喱食谱:

PREFIX rdfs: <htp://ww.w3.org/2000/01/rdf-schema#>
PREFIX recipe: <htp://linkedrecipes.org/schema/>

SELECT ?label ?recipe 
WHERE{ 
?food rdfs:label ?label2 . 
?food recipe:ingredient_of ?recipe .
?recipe a recipe:Recipe . 
?recipe rdfs:label ?label.  

FILTER (REGEX(STR(?label2), 'curry', 'i'))
}

但是我怎么能找到咖喱和鸡肉的食谱呢?

1 个答案:

答案 0 :(得分:1)

这应该找到咖喱和鸡肉:

PREFIX rdfs: <htp://ww.w3.org/2000/01/rdf-schema#>
PREFIX recipe: <htp://linkedrecipes.org/schema/>

SELECT ?label ?recipe { 
    ?recipe a recipe:Recipe . 
    ?recipe rdfs:label ?label.  

    ?curry recipe:ingredient_of ?recipe .
    ?curry rdfs:label ?curry_label . 
    FILTER (REGEX(STR(?curry_label), 'curry', 'i'))

    ?chicken recipe:ingredient_of ?recipe .
    ?chicken rdfs:label ?chicken_label . 
    FILTER (REGEX(STR(?chicken_label), 'chicken', 'i'))
}