【发布时间】:2016-05-14 13:08:14
【问题描述】:
我的本体有 2 个类:foodfoodSource。
我想使用 SPARQL 查询获取具有 2 种 foodSource 的类 food 的数据:
SELECT ?food ?foodSource ?foodSource2
WHERE {
{
?foodSource mpasi:data_memerlukanBahan ?memerlukanBahan.
?food ?memerlukanBahan ?value.
FILTER regex(str(?foodSource),"carrot")
}
UNION
{
?foodSource2 mpasi:data_memerlukanBahan ?memerlukanBahan.
?food ?memerlukanBahan ?value.
FILTER regex(str(?foodSource2),"tomato")
}
}
order by ?food
我得到了正确的结果。但后来我想避免一些食物来源。那么,我怎样才能得到没有食物来源的食物呢?例如,我有 3 种食物:
- 克得来粥
- 苹果碎
- 番茄汤
然后我想要里面没有苹果的食物。所以,很自然地,我只得到了可得来粥和番茄汤。 我可以使用 !regex 获取它吗?
FILTER (!regex(str(?foodSource),"apple")).
【问题讨论】:
-
Regex 支持 union 和 negation,这可能比通过 SPARQL union 和 MINUS 编写更有效。