gpt4 book ai didi

sparql - 对同一属性的 SPARQL 结果进行分组?

转载 作者:行者123 更新时间:2023-12-03 06:53:46 28 4
gpt4 key购买 nike

我有以下 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" }
}
]
}
}

最佳答案

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

GROUP_CONCAT 但它生成一个字符串,该字符串是 GROUP 中字符串的“,”分隔的连接。它将进行解析。引擎可以具有扩展聚合函数。

关于sparql - 对同一属性的 SPARQL 结果进行分组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23121038/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com