SPARQL concat加上多个字段上的组_concat
我无法更改以下RDF结构: 可以将多个工作分配关联到每个员工(经理)。我想要的输出是(包括单词“in”和“&”): 在SPARQL concat加上多个字段上的组_concat,sparql,rdf,owl,Sparql,Rdf,Owl,我无法更改以下RDF结构: 可以将多个工作分配关联到每个员工(经理)。我想要的输出是(包括单词“in”和“&”): 在Sparql中是否有这样做的方法 这就是我到目前为止所做的: select ?name group_concat(DISTINCT ?description; separator("&")) where { ?employee :hasName ?name { select concat(?name, "In", ?location) ?employee
Sparql
中是否有这样做的方法
这就是我到目前为止所做的:
select ?name group_concat(DISTINCT ?description; separator("&"))
where
{
?employee :hasName ?name
{
select concat(?name, "In", ?location)
?employee ^:hasManager/:hasAsstName ?name
?employee ^:hasManager/:hasLocation ?location
}
}
这给了我空的员工姓名和大量的描述。它似乎没有反映出我的期望值。假设嵌套查询很好,您应该在那里分配一个变量来分组连接,然后对所有未连接的变量的结果进行分组。查询应该如下所示:
select ?name (group_concat(DISTINCT ?description; separator = " & ") as ?descriptions)
where
{
?employee :hasName ?name
{
select (concat(?name, " in ", ?location) AS ?description)
?employee ^:hasManager/:hasAsstName ?name
?employee ^:hasManager/:hasLocation ?location
}
}
GROUP BY ?name
请注意GROUP\u CONCAT
的语法
如果删除子查询,速度会快得多。因为我没有您的数据,这里有一个非常类似的关于DBpedia的查询,不使用子查询:
SELECT ?name (GROUP_CONCAT(DISTINCT ?SpouseInfo; separator = " & ") AS ?SpousesInfo)
{
?name a foaf:Person;
dbo:spouse ?spouse.
?spouse dbo:residence/rdfs:label ?residence;
rdfs:label ?spouse_name
BIND (CONCAT(?spouse_name, " lives in ",?residence) AS ?SpouseInfo)
}
GROUP BY ?name
ORDER BY ?name
LIMIT 100
以下是。您是否有一个可以部分说明问题的查询?如果有,您的问题将包括在内。如果没有,为什么没有?谢谢!我遗漏了添加“as”说明“.有更好的方法吗?查询似乎需要很长时间才能执行,有时只是超时。哪个三重存储。你的数据有多大。group_concat通常成本很高,并且根据实现可能会阻止某些优化。您可以通过删除嵌套查询并将其内容放入上层查询来加快优化速度;接近十亿倍。但是,您确定这是正确的查询逻辑吗?我提供了一个关于DBpedia的非常类似的查询的示例。如果有帮助,请告诉我。
SELECT ?name (GROUP_CONCAT(DISTINCT ?SpouseInfo; separator = " & ") AS ?SpousesInfo)
{
?name a foaf:Person;
dbo:spouse ?spouse.
?spouse dbo:residence/rdfs:label ?residence;
rdfs:label ?spouse_name
BIND (CONCAT(?spouse_name, " lives in ",?residence) AS ?SpouseInfo)
}
GROUP BY ?name
ORDER BY ?name
LIMIT 100