简体   繁体   English

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

[英]How to exclude resources with a specific rdf:type from SPARQL results?

I have this query SPARQL that I ran on it.dbpedia.org/sparql: 我有这个查询SPARQL我在它上运行.dbpedia.org/sparql:

select ?resource where {
  ?resource rdfs:label "Piemonte"@it
}

I get this result: 我得到这个结果:

http://it.dbpedia.org/resource/Categoria:Piemonte
http://it.dbpedia.org/resource/Piemonte

I would like to have only http://it.dbpedia.org/resource/Piemonte as a result. 我希望只有http://it.dbpedia.org/resource/Piemonte I am trying to write this query SPARQL to delete http://it.dbpedia.org/resource/Categoria:Piemonte from the results: 我试图写这个查询SPARQL从结果中删除http://it.dbpedia.org/resource/Categoria:Piemonte

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

because I noticed that http://it.dbpedia.org/resource/Categoria:Piemonte has the object skos:Concept whereas the http://it.dbpedia.org/resource/Piemonte doesn't, but I get the same result. 因为我注意到http://it.dbpedia.org/resource/Categoria:Piemonte有对象skos:Concepthttp://it.dbpedia.org/resource/Piemonte没有,但我得到相同的结果。 Why? 为什么? What am I doing wrong here? 我在这做错了什么?

I also tries adding LIMIT 1 , but the result was http://it.dbpedia.org/resource/Categoria:Piemonte , since the results aren't guaranteed to be in the same order. 我也尝试添加LIMIT 1 ,但结果是http://it.dbpedia.org/resource/Categoria:Piemonte ,因为结果不保证是相同的顺序。

With a filter like FILTER (rdf:type != skos:Concept) you're just asking whether two constants are unequal. 使用像FILTER (rdf:type != skos:Concept)这样的FILTER (rdf:type != skos:Concept)器,你只是问两个常量是否不相等。 The URIs rdf:type and skos:Concept are, of course, different. URIs rdf:typeskos:Concept当然是不同的。

What you want is a resource that doesn't have the value skos:Concept for the property rdf:type . 你想要的是一个没有skos:Concept值的资源skos:Concept属性rdf:type skos:Concept You'd indicate that it does have that by ?resource rdf:type skos:Concept . 你会指出它确实?resource rdf:type skos:Concept So your query just needs a filter that ensures that that triple does not exist in the data. 因此,您的查询只需要一个过滤器,以确保数据中不存在该三元组。 On the Italian DBpedia, you can ask the following and get just one result back. 在意大利语DBpedia上,您可以询问以下内容并获得一个结果。

select ?resource where {
  ?resource rdfs:label "Piemonte"@it
  filter not exists { ?resource rdf:type skos:Concept }
}

SPARQL results SPARQL结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM