某个属性在 SPARQL 中应用了多少次?
如果我有一个 SPARQL 查询,
PREFIX foaf <http://xmlns.com/foaf/0.1/>
SELECT ?name
WHERE {
?x foaf:name ?name.
?x foaf:knows ?y.
}
要选择某个 x 的名称,谁知道某个 y。我怎样才能只选择那些恰好认识另外 3 个人(或任何其他数字)的人的名字?
另外,作为一个附带问题 - 这个问题有更好的标题吗?哪个使用更好的术语来澄清问题?
谢谢
If I have a SPARQL query say,
PREFIX foaf <http://xmlns.com/foaf/0.1/>
SELECT ?name
WHERE {
?x foaf:name ?name.
?x foaf:knows ?y.
}
to select the name of some x, who knows some y. How could I select only the names of those people who know exactly 3 other people (or any other number)?
Also, as a side question - is there a better title for this question? One which uses better terminology to clarify the problem?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 SPARQL 1.1 及其新功能来实现这一目标:GROUP BY、HAVING 和 SUBQUERIES 。像这样的东西就可以完成这项工作:
不幸的是,并非所有 SPARQL 引擎都支持所有这些功能。我知道 Jena/ARQ 和 Virtuoso 支持它们。
如果您使用的 SPARQL 引擎不支持这些功能,那么我建议运行查询:
...并使用几行客户端代码以编程方式计算查询中所需的其余逻辑。
You could achieve that with SPARQL 1.1 and it new features: GROUP BY, HAVING and SUBQUERIES. Something like this would do the job:
Unfortunately not all SPARQL engines support all these features together. That I know Jena/ARQ and Virtuoso support them.
If you are working with an SPARQL engine that doesn't support these features then I recommend to run the query:
... and programatically compute the rest of the logic that you need in the query with few lines of client-side code.