我有以下 sparql 查询:
PREFIX spec: <http://rdfs.org/sioc/spec/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX constraint: <http://purl.org/vocab/constraint/constraint#>
SELECT
(sample(?FName) as ?fName)
(sample(?Midname) as ?midname)
(sample(?User) as ?user)
(GROUP_CONCAT(DISTINCT ?userRole; separator='; ') AS ?UserRole)
WHERE {
GRAPH <http://example.com/>
{
?User spec:email ?Email .
?User foaf:firstName ?FirstName .
?User foaf:surname ?Midname .
OPTIONAL
{
?User constraint:containsConstraint ?constraint .
?constraint constraint:constrains ?userRoleUri .
?userRoleUri spec:name ?userRole.
}
FILTER (str(?userRoleUri) IN("http://example.com/roles/admin", "http://example.com/roles/moderator"))
}
} GROUP BY ?FName ORDER BY ASC(?FName)
此查询的作用是返回匹配的用户。 因此,如果用户“A”列出了 3 个角色:编辑者、管理员和主持人,则它仅显示用户的两个角色。 像:
A - Mid - <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0c6d4c6d6e6f226361" rel="noreferrer noopener nofollow">[email protected]</a> - admin;moderator
我想通过查询做的是: 由于用户 A 匹配任何给定的过滤条件,因此应列出其所有角色。有没有办法改进这个查询?我也尝试过在过滤器中使用子选择和正则表达式,但是:(
提前致谢 斯帕克勒
最佳答案
answers.Sematicweb.com 上提出的解决方案在很大程度上解决了问题。这正是我所需要的,但是,很有可能。
**对此的回答:** http://answers.semanticweb.com/questions/20016/sparql-filter-get-all-details-of-a-match
谢谢
关于Sparql过滤器: get all details of a match,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13859034/