On 26/06/13 07:40, Katja Siegemund wrote:
Hello,

I'm trying to get negated data with SPARQL (individuals of an ontology
that do not belong to a certain class), but I could not figure out how
to write the appropriate query therefore. It's working for object
properties and using FILTER NOT EXIST, but this one I can't manage.

Could you help me out here please?

The query should somehow look like this:

"PREFIX
ro:<http://www.semanticweb.org/ontologies/2012/4/test_ontology.owl#>
SELECT ?r WHERE NOT{?r a ro:RelatedRequirement}";

The NOT is just placed here to indicate that I want to get all
individuals that are NOT instances of the ontology class
RelatedRequirement.

Thanks,
Katja

(I don't know the data model)

The approach is to find everything meeting a more general condition then remove the things that match the specific condition
{?r a ro:RelatedRequirement}.

The more you can limit the initial "find everything / general condition", the faster the query will go. e.g if they will all have a particular type, :TypeALL, then use :TypeAll not ?T below.

Then either of:

## Everything with an rdf:type but not ro:RelatedRequirement
SELECT DISTINCT ?r WHERE
{ ?r a ?T
  FILTER NOT EXISTS { ?r a ro:RelatedRequirement }
}

SELECT DISTINCT ?r WHERE
{ ?r a ?T
  MINUS { ?r a ro:RelatedRequirement }
}

        Andy

PS Please start a new thread for a new question - if you reply to an existing message, even if you change the subject line, then people who are ignoring the thread will ignore your new question as well.


Reply via email to