@@ -426,5 +426,44 @@ def test_ConfusionMatrixQuery(self):
426426 self .assertEqual (int (sparql_results .bindings [0 ]["fp" ]), 1 )
427427 self .assertEqual (int (sparql_results .bindings [0 ]["tn" ]), 1 )
428428
429+ def test_DataSomeValuesFrom_with_TopOWLDatatype_in_Complement (self ):
430+ """Test for issue #212: Incorrect SPARQL translation for OWLDataSomeValuesFrom with rdfs:Literal"""
431+ from owlapy .class_expression import OWLClass , OWLObjectIntersectionOf , OWLObjectComplementOf , OWLDataSomeValuesFrom
432+ from owlapy .owl_property import OWLDataProperty
433+ from owlapy .owl_literal import TopOWLDatatype
434+
435+ # Create ((CONTEXT_POSITION_MARKER ⊓ ∃mouse_lymph.Literal) ⊓ ¬∃salmonella.Literal)
436+ ce = OWLObjectIntersectionOf ((
437+ OWLObjectIntersectionOf ((
438+ OWLClass (IRI ('http://owlapy.internal/' , 'CONTEXT_POSITION_MARKER' )),
439+ OWLDataSomeValuesFrom (
440+ property = OWLDataProperty (IRI ('http://dl-learner.org/carcinogenesis#' , 'mouse_lymph' )),
441+ filler = TopOWLDatatype
442+ )
443+ )),
444+ OWLObjectComplementOf (
445+ OWLDataSomeValuesFrom (
446+ property = OWLDataProperty (IRI ('http://dl-learner.org/carcinogenesis#' , 'salmonella' )),
447+ filler = TopOWLDatatype
448+ )
449+ )
450+ ))
451+
452+ converter = Owl2SparqlConverter ()
453+ result = converter .convert ('?pos' , ce , True , False )
454+ sparql = "" .join (result )
455+
456+ # Verify the SPARQL is valid and doesn't contain the incorrect ?pos ?s_X ?s_Y pattern
457+ # The bug was producing: ?pos ?s_2 ?s_3 . between the two FILTER statements
458+ self .assertNotIn ('?pos ?s_2 ?s_3' , sparql )
459+
460+ # Verify the correct patterns are present
461+ self .assertIn ('?pos a <http://owlapy.internal/CONTEXT_POSITION_MARKER>' , sparql )
462+ self .assertIn ('?pos <http://dl-learner.org/carcinogenesis#mouse_lymph>' , sparql )
463+ self .assertIn ('FILTER ( isLiteral ( ?s_1 ) )' , sparql )
464+ self .assertIn ('FILTER NOT EXISTS' , sparql )
465+ self .assertIn ('<http://dl-learner.org/carcinogenesis#salmonella>' , sparql )
466+ self .assertIn ('FILTER ( isLiteral ( ?s_2 ) )' , sparql ) # Inside the FILTER NOT EXISTS
467+
429468if __name__ == '__main__' :
430469 unittest .main ()
0 commit comments