如何从SPARQL结果中排除具有特定rdf:type的资源?

Mus*_*h87 4 java rdf semantic-web rdfs sparql

我有这个查询SPARQL我在它上运行.dbpedia.org/sparql:

select ?resource where {
  ?resource rdfs:label "Piemonte"@it
}
Run Code Online (Sandbox Code Playgroud)

我得到这个结果:

http://it.dbpedia.org/resource/Categoria:Piemonte
http://it.dbpedia.org/resource/Piemonte
Run Code Online (Sandbox Code Playgroud)

我希望只有http://it.dbpedia.org/resource/Piemonte.我试图写这个查询SPARQL 从结果中删除http://it.dbpedia.org/resource/Categoria:Piemonte:

select ?resource where {
  ?resource rdfs:label "Piemonte"@it
  FILTER (rdf:type != skos:Concept)
}
Run Code Online (Sandbox Code Playgroud)

因为我注意到http://it.dbpedia.org/resource/Categoria:Piemonte有对象skos:Concepthttp://it.dbpedia.org/resource/Piemonte没有,但我得到了相同的结果.为什么?我在这做错了什么?

我也尝试添加LIMIT 1,但结果是http://it.dbpedia.org/resource/Categoria:Piemonte,因为结果不保证是相同的顺序.

Jos*_*lor 6

使用像FILTER (rdf:type != skos:Concept)你只是问两个常量是否不相等的过滤器.这些URI rdf:typeskos:Concept是的,当然,不同的.

您想要的是一个没有skos:Concept该属性值的资源rdf:type.你表明它确实有这个?resource rdf:type skos:Concept.因此,您的查询只需要一个过滤器,以确保数据中不存在该三元组.在意大利语DBpedia上,您可以询问以下内容并获得一个结果.

select ?resource where {
  ?resource rdfs:label "Piemonte"@it
  filter not exists { ?resource rdf:type skos:Concept }
}
Run Code Online (Sandbox Code Playgroud)

SPARQL结果

  • @Musich87评论是要求澄清问题/答案,如果您有新问题,请将其作为新问题链接回原始问题作为相关参考 (3认同)