In a previous question
SPARQL if an instance has a property, others must as well
I asked that if i have an instance that has a value for a specific predicate, then the all the output of my sparql query must have the same value for the same predicate.
I got an excellent answer there,
now I am trying to expand it because i've found a new scenario,
the new scenario is:
if an instance has a value to a specific predicate then all the output items must either have the same value for the same predicate or if they have another value, these two values must be from the same class
I extended that sparql query to the following:
PREFIX : <http://example.org/rs#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?item ?predicate ?similarity where
{
values ?x {:instance1}
?x ?predicate ?value.
?item ?predicate ?value.
?predicate :hasSimilarityValue ?similarity.
filter (?x != ?item)
filter not exists {
?x ?p ?v1.
?v1 a ?class.
?p rdfs:subPropertyOf :isCriticalPredicate.
filter not exists {
?item ?p ?v2.
?p rdfs:subPropertyOf :isCriticalPredicate.
?v2 a ?class.
?class rdfs:subClassOf :ImportantClass
}
}
}
and here is my data:
@prefix : <http://example.org/rs#>
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
:instance1 :p1 :value1.
:instance2 :p1 :value2.
:p1 :hasSimilarityValue 0.5.
:value1 a :class1.
:value2 a :class1.
:class1 rdfs:subClassOf :ImportantClass.
:p1 rdfs:subPropertyOf :isCriticalPredicate.
but the result is always empty i don't know why.
note1
by specific predicate, i mean the predicate that are rdfs:subClassOf :isCriticalPredicate
by specific class, I mean that class that are rdfs:subClassOf :ImportantClass