[英]Group Concat using sparql query
Can some one help me how to use group_concat in sparql query.有人可以帮助我如何在 sparql 查询中使用 group_concat。 When i am using in the database it is pulling out iri from the data.当我在数据库中使用它时,它会从数据中提取 iri。 How to pull the the labels for the objects present in the database using group_concat.如何使用 group_concat 提取数据库中存在的对象的标签。
You will usually have IRIs with a label.您通常会有带有标签的 IRI。 Now, to return labels only, a query like this will work:现在,只返回标签,这样的查询将起作用:
SELECT ?item ?label
WHERE {
?item rdfs:label ?label
}
Note that rdfs:label
is conventionally used for labels, but any name can be used - it depends on the data that you have.请注意, rdfs:label
通常用于标签,但可以使用任何名称 - 这取决于您拥有的数据。
Now, imagine we want to find a GROUP_CONCAT
of children's names, grouped by mother.现在,假设我们想要找到一个由母亲分组的孩子名字的GROUP_CONCAT
。 First, the query for the children and labels looks like this:首先,对子项和标签的查询如下所示:
SELECT ?mother ?child ?label
WHERE {
?mother :hasChild ?child .
?child rdfs:label ?label .
}
Notice that ?mother
and ?child
will be bound to IRIs here, and ?label
to a string.请注意, ?mother
和?child
将在此处绑定到 IRI,而?label
将绑定到字符串。
Now for the GROUP_CONCAT
, you will just need a query like:现在对于GROUP_CONCAT
,您只需要如下查询:
SELECT ?mother (GROUP_CONCAT(?label; SEPARATOR=", ") AS ?concat)
WHERE {
?mother :hasChild ?child .
?child rdfs:label ?label .
}
GROUP BY ?mother
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.