选择(组合)多个属性值 - SPARQL/RDF [英] Select (combine) multiple attribute values - SPARQL / RDF

查看:40
本文介绍了选择(组合)多个属性值 - SPARQL/RDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下的 RDF:

resource: r1 <dc:title>Mathematics</dc:title><dc:title>Chemistry</dc:title><dc:size>39</dc:size>
resource:r2 <dc:title>Biology</dc:title><dc:size>42</dc:size>

我有这个 SPARQL 查询来提取值:

And I have this SPARQL query to extract the values:

PREFIX dc: <http://purl.org/dc/elements/1.1/> 
select distinct ?resource ?title ?size  where {
    ?resource dc:title ?title
    ?resource dc:size ?size
}

结果:

resource  title        size 
r1        Mathematics  39
r1        Chemistry    39
r2        Biology      42

但我想得到以下结果:

resource  title                   size
r1        Mathematics, Chemistry  39
r2        Biology                 42

我该如何解决这个问题?

How can I solve this problem?

推荐答案

把 ?resource 组合起来就可以了.这也允许您使用 GROUP_CONCAT 将标题转换为字符串(确切顺序取决于评估).

To get ?resource combined group on it. This also allows you to use GROUP_CONCAT to get the titles truned into a string (the exact order will depend on evaluation).

PREFIX dc: <http://purl.org/dc/elements/1.1/> 
select ?resource ?size (GROUP_CONCAT(?title) AS ?titles) where {
    ?resource dc:title ?title
    ?resource dc:size ?size
} GROUP BY ?resource ?size

但您可能更喜欢在应用程序代码中进行排序和细粒度处理:

But you may be better of with sorting and doing the fine grained processing in application code:

ORDER BY ?resource ?size ?title

而不是GROUP BY.

这篇关于选择(组合)多个属性值 - SPARQL/RDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆