为同一属性分组SPARQL结果?

时间:2014-04-16 22:08:50

标签: 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" }
      }
    ]
  }
}

1 个答案:

答案 0 :(得分:2)

不是真的。结果格式中没有数组数据类型。您可以通过处理结果来创建此关联,ORDER BY ?subsidiary ?employees会将行放在您想要折叠的位置附近。

GROUP_CONCAT但它会产生一个字符串,即&#34;,&#34;在GROUP中分隔的字符串连接。它会被解析。引擎可能具有扩展聚合函数。