Currently the instance method in the class TripleStore will convert the owl class expression to a SPARQL query.
This method accepts an argument direct which specifies whether indirect individuals covered by that class expression should also be retrieved or not. The way this is handled is by replacing the root variable to search for sublcasses of a certain class like following:
if not direct:
ce_to_sparql = ce_to_sparql.replace(
"?x a ",
"?x a ?some_cls. \n ?some_cls <http://www.w3.org/2000/01/rdf-schema#subClassOf>* ",
)
Now lets consider the following example class expression: (¬Daughter) ⊓ Female
For this expression the following SPARQL query is generated, considering that direct=False the following query will be generated:
SELECT
DISTINCT ?x WHERE {
?x ?s_1 ?s_2 .
FILTER NOT EXISTS {
?x a ?some_cls.
?some_cls <http://www.w3.org/2000/01/rdf-schema#subClassOf>* <http://www.benchmark.org/family#Daughter> .
}
?x a ?some_cls.
?some_cls <http://www.w3.org/2000/01/rdf-schema#subClassOf>* <http://www.benchmark.org/family#Female> .
}
The issue here is that ?some_cls is used inside and outside FILTER NOT EXISTS which will return incorrect results.
A solution (that covers at least this scenario) would be to decouple the variables ?some_cls and use uneque name for each of them.
In the code this would be translated to replacing each occurrence of ?x with ?some_cls + a counter that is increased for each occurrence.
That being said, there is still a need to verify if the indirect search is performed correctly. If in doubt, leave default to direct=True.
Currently the
instancemethod in the classTripleStorewill convert the owl class expression to a SPARQL query.This method accepts an argument
directwhich specifies whether indirect individuals covered by that class expression should also be retrieved or not. The way this is handled is by replacing the root variable to search for sublcasses of a certain class like following:Now lets consider the following example class expression:
(¬Daughter) ⊓ FemaleFor this expression the following SPARQL query is generated, considering that
direct=Falsethe following query will be generated:The issue here is that
?some_clsis used inside and outsideFILTER NOT EXISTSwhich will return incorrect results.A solution (that covers at least this scenario) would be to decouple the variables
?some_clsand use uneque name for each of them.In the code this would be translated to replacing each occurrence of
?xwith?some_cls+ a counter that is increased for each occurrence.That being said, there is still a need to verify if the indirect search is performed correctly. If in doubt, leave default to
direct=True.