Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

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. I am trying to write this query SPARQL to delete http://it.dbpedia.org/resource/Categoria:Piemonte from the results:

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. 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.

like image 529
Musich87 Avatar asked Jun 11 '14 15:06

Musich87


People also ask

What types of queries does SPARQL support select all that apply?

SPARQL contains capabilities for querying required and optional graph patterns along with their conjunctions and disjunctions. SPARQL also supports aggregation, subqueries, negation, creating values by expressions, extensible value testing, and constraining queries by source RDF graph.

What is the result type of an SPARQL ask query?

SPARQL also supports extensible value testing and constraining queries by source RDF graph. The results of SPARQL queries can be results sets or RDF graphs.

What is optional SPARQL?

OPTIONAL is a binary operator that combines two graph patterns. The optional pattern is any group pattern and may involve any SPARQL pattern types. If the group matches, the solution is extended, if not, the original solution is given (q-opt3. rq).

What is FOAF in SPARQL?

Dataset: Friend of a Friend (FOAF) @prefix card: <http://www.w3.org/People/Berners-Lee/card#> . @prefix foaf: <http://xmlns.com/foaf/0.1/> .


1 Answers

With a filter like FILTER (rdf:type != skos:Concept) you're just asking whether two constants are unequal. The URIs rdf:type and skos:Concept are, of course, different.

What you want is a resource that doesn't have the value skos:Concept for the property rdf:type. You'd indicate that it does have that by ?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.

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

SPARQL results

like image 196
Joshua Taylor Avatar answered Oct 01 '22 03:10

Joshua Taylor