2012-09-08 100 views
1

好吧,假設我需要提取所有包含2/3成分的食譜。 食譜被表示爲鏈接數據,這是使用的本體http://linkedrecipes.org/schema。 我知道如何查找菜譜咖喱:用於RECIPE選擇的SPARQL查詢

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

這應該找到咖喱雞:

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')) 
} 
+0

由於它的工作......你剛纔忘了WHERE語句,但它的罰款。感謝cygry ... –