I have the following scenario modelled in OWL:
Producer
----producesResource--->
Resource
<------consumesResource ----
Consumer
Producer
, Resource
and Consumer
are OWL Classes, while producesResource
and consumesResource
are object properties. The scenario is quite intuitive in that that each producer produces one or more resources that is consumed by one or more consumers. Conversely, each consumer can consume one or more resources. The ontology is populated with instances / individuals accordingly.
I would like to check if there exists a resource that is consumed by a consumer that is not produced by a Producer. What is an elegant way to get this information via a:
Negations are possible in SPARQL using the NOT BOUND filter or more easily in SPARQL 1.1 using MINUS:
SELECT ?resource WHERE
{
?resource a :Resource.
?consumer a :Consumer;
?consumer :consumesResource ?resource.
MINUS {?producer a :Producer; :producesResource ?resource.}
}
You can also use ASK
to get a boolean result but SELECT
allows easier debugging to verify if your query is working correctly.
As SHACL allows integrating SPARQL queries, this answers your second question too but in that case it is easier to just use the SPARQL query on its own.