Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selecting using sparql based on 'triple does not exist'

Tags:

I need a little help selecting the right triples from my store....

<a> a <type/1> . <b> a <type/1> . <c> a <type/1> . <c> a <type/2> . 

i want to select only elements which are type/1 and not type/2

What is the best way to achieve this using a sparql select query?

am looking for omething like:

select ?a where  {      ?a a <type/1> .     !{ ?a a <type/2> } } 

Thanks,

:)

like image 664
significance Avatar asked Aug 17 '11 18:08

significance


People also ask

How does SPARQL work?

SPARQL sees your data as a directed, labeled graph, that is internally expressed as triples consisting of subject, predicate and object. Correspondingly, a SPARQL query consists of a set of triple patterns in which each element (the subject, predicate and object) can be a variable (wildcard).

What is construct query in SPARQL?

The CONSTRUCT query form returns an RDF graph. The graph is built based on a template which is used to generate RDF triples based on the results of matching the graph pattern of the query.

What types of queries does SPARQL support?

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.


1 Answers

An alternative SPARQL 1.1 solution is to use MINUS e.g.

SELECT ?a WHERE {   ?a a <type/1> .   MINUS { ?a a <type/2> . } } 

MINUS subtracts solutions that match its triple pattern from the existing matches.

In most cases using FILTER NOT EXISTS { } and MINUS { } are equivalent but beware there are some corner cases where this is not true - see the SPARQL 1.1 specification for some examples of this.

like image 128
RobV Avatar answered Nov 09 '22 01:11

RobV