SPARQL:如何将变量限制为命名空间?

发布于 2025-02-12 14:17:23 字数 329 浏览 2 评论 0原文

考虑以下SPARQL查询:

PREFIX basics: <http://example.org/basic-knowledge/>
PREFIX special: <http://example.org/special-predicates/>

SELECT ?S ?P ?O
WHERE
{

 ?S ?P ?O.

}

这将产生所有三元组。

我如何将结果限制为谓词?p来自命名空间的三个三元组,而precix special:?

Consider the following SPARQL query:

PREFIX basics: <http://example.org/basic-knowledge/>
PREFIX special: <http://example.org/special-predicates/>

SELECT ?S ?P ?O
WHERE
{

 ?S ?P ?O.

}

This yields all triples.

How can I restrict the result to those triples where the predicate ?P is from the namespace with the prefix special:?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最后的乘客 2025-02-19 14:17:23

这可以通过字符串测试来完成。 str()将URIS变成字符串。

FILTER(strStarts(str(?P), str(special:)))

注意special:由解析器替换为完整的URI:http://example.org/special-predicates,因此executiuon是

FILTER(strStarts(str(?P), str(<ttp://example.org/special-predicates>)))

可运行的示例:

PREFIX ns1: <http://example/>
PREFIX ns2: <http://ex/>

SELECT * {
 VALUES ?x { ns1:abc ns2:xyz }
 FILTER(strstarts(str(?x), str(ns1:)))
}

This can be done with a string test. str() turns URIs into strings.

FILTER(strStarts(str(?P), str(special:)))

note the special: is replaced by the parser with the full URI: http://example.org/special-predicates so the executiuon is

FILTER(strStarts(str(?P), str(<ttp://example.org/special-predicates>)))

Runnable example:

PREFIX ns1: <http://example/>
PREFIX ns2: <http://ex/>

SELECT * {
 VALUES ?x { ns1:abc ns2:xyz }
 FILTER(strstarts(str(?x), str(ns1:)))
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文