1

好的,假设我需要提取所有包含 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'))
}

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

4

1 回答 1

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'))
}
于 2012-09-08T19:29:11.260 回答