我在自己的本体上编写了一个SPARQL查询,它提供了重复的记录,为此我也使用了group_concat,我的查询是
SELECT ?Movie (str(?y) as ?Rating) (group_concat (?z;separator=",") as ?Director)
{ ?Movie :rating ?y;
:directedBy ?z
FILTER regex(str(?Movie),'Fantastic_Four') }
GROUP BY ?y ?Movie
此查询为我提供了所需的结果,但Director的输出方式如下:
http://www.semanticweb.org/administrator/ontologies/2017/2/Ontology-Schema_Movie#Josh_Trank,http://www.semanticweb.org/administrator/ontologies/2017/2/Ontology-Schema_Movie#Joshua_Trank
我想知道为什么这个整个URI来了,如何删除它并且只在我的结果中打印Josh_Trank,Joshua_Trank?
答案 0 :(得分:1)
RDF资源由URI标识,这就是连接URI列表的原因。如果你需要一些人类可读的名字
PREFIX : <http://www.semanticweb.org/administrator/ontologies/2017/2/Ontology-Schema_Movie#>
SELECT ?Movie (str(?y) as ?Rating)
(group_concat (?director_name;separator=",") as ?Director) {
?Movie :rating ?y;
:directedBy ?z
FILTER regex(str(?Movie),'Fantastic_Four')
BIND(strafter(str(?z),str(:)) as ?director_name)
}
GROUP BY ?y ?Movie
rdfs:label
(或类似的东西),如果存在URI的人类可读名称