是否对同一属性的SPARQL结果进行分组? [英] Grouping SPARQL results for the same property?

查看:11
本文介绍了是否对同一属性的SPARQL结果进行分组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下SPARQL查询:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>

SELECT ?subsidiary ?employees
WHERE {
    <http://dbpedia.org/resource/Google> dbo:subsidiary ?subsidiary;
                                   dbo:numberOfEmployees ?employees .
}

我收到以下响应:

{
  "head": {
    "vars": [ "subsidiary" , "employees" ]
  } ,
  "results": {
    "bindings": [
      {
        "subsidiary": { "type": "uri" , "value": "http://dbpedia.org/resource/YouTube" } ,
        "employees": { "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "type": "typed-literal" , "value": "53861" }
      } ,
      {
        "subsidiary": { "type": "uri" , "value": "http://dbpedia.org/resource/Motorola_Mobility" } ,
        "employees": { "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "type": "typed-literal" , "value": "53861" }
      } ,
      {
        "subsidiary": { "type": "uri" , "value": "http://dbpedia.org/resource/Picnik" } ,
        "employees": { "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "type": "typed-literal" , "value": "53861" }
      }
    ]
  }
}

多次返回员工数量,因为他们是与查询资源相关联的多个子公司。是否可以将所有这些子公司合并到一个列表中,并获得更多内容:

{
  "head": {
    "vars": [ "subsidiary" , "employees" ]
  } ,
  "results": {
    "bindings": [
      {
        "subsidiary": { "type": "uri" , "value": [
             "http://dbpedia.org/resource/YouTube",
             "http://dbpedia.org/resource/Motorola_Mobility",
             "http://dbpedia.org/resource/Picnik"
          ]
        } ,
        "employees": { "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "type": "typed-literal" , "value": "53861" }
      }
    ]
  }
}

推荐答案

不完全是。结果格式中没有AN数组数据类型。您可以通过处理结果来创建此关联,ORDER BY ?subsidiary ?employees将放置您要折叠的相邻行。

GROUP_CONCAT,但它会生成一个字符串,该字符串是组中字符串的","分隔连接。它会在解析。引擎可以具有扩展聚合函数。

这篇关于是否对同一属性的SPARQL结果进行分组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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