sszuev opened a new issue, #1264:
URL: https://github.com/apache/jena/issues/1264

   The test bellow fails for jena-shacl but passes for topbraid-shacl.
   
   test:
   ```java
   public class JenaShaclBugTest {
   
       @Test
       public void testJenaShacl() {
           testShaclRules(JenaShaclBugTest::runJenaShaclRules);
       }
   
       @Test
       public void testTopbraidShacl() {
           testShaclRules(JenaShaclBugTest::runTopbraidShaclRules);
       }
   
       private void testShaclRules(BinaryOperator<Model> ruleEngine) {
           Model dataModel = createDataGraph();
           dataModel.write(System.out, "ttl");
           Model rules = createShapeGraph();
           rules.write(System.out, "ttl");
           Model result = ruleEngine.apply(dataModel, rules);
           result.write(System.out, "ttl");
   
           List<Statement> reports = result
                   .listStatements(null, RDF.type, 
asProperty(SHACL.ValidationReport, rules)).toList();
           Assertions.assertEquals(1, reports.size());
           List<Resource> results = reports.get(0).getSubject()
                   .listProperties(asProperty(SHACL.result, 
result)).mapWith(Statement::getResource).toList();
           Assertions.assertEquals(1, results.size());
       }
   
       private static Model runJenaShaclRules(Model dataModel, Model rules) {
           ValidationReport res = 
ShaclValidator.get().validate(rules.getGraph(), dataModel.getGraph());
           return res.getModel();
       }
   
       private static Model runTopbraidShaclRules(Model dataModel, Model 
shapesModel) {
           Resource report = 
org.topbraid.shacl.validation.ValidationUtil.validateModel(dataModel, 
shapesModel, false);
           return report.getModel();
       }
   
       private static Model createDataGraph() {
           String ns = "http://example#";;
           Model m = ModelFactory.createDefaultModel()
                   .setNsPrefixes(PrefixMapping.Standard)
                   .setNsPrefix("ex", ns);
           Resource classA = m.createResource(ns + "A");
           Resource classB = m.createResource(ns + "B");
           m.createResource(ns + "Individual", classA);
           classA.addProperty(RDFS.subClassOf, classB);
           return m;
       }
   
       private static Model createShapeGraph() {
           String ns = "http://example#";;
           Model m = ModelFactory.createDefaultModel()
                   .setNsPrefixes(PrefixMapping.Standard)
                   .setNsPrefix("sh", SHACL.getURI())
                   .setNsPrefix("ex", ns);
           m.createProperty("http://example/test";).addProperty(OWL.imports, 
m.createProperty(SHACL.getURI()));
   
           Property customPredicate = m.createProperty(ns + "custom");
           Resource specialTarget = m.createResource(ns + "SpecialTarget");
           // a sh:NodeShape
           m.createResource(ns + "AShape", asProperty(SHACL.NodeShape, m))
                   .addProperty(asProperty(SHACL.target, m), specialTarget)
                   .addProperty(customPredicate, RDFS.subClassOf)
           ;
   
           // a sh:ConstraintComponent
           m.createResource(ns + "CustomConstraintComponent")
                   .addLiteral(asProperty(SHACL.message, m), "Fail: can't find 
object for predicate")
                   .addProperty(RDF.type, asProperty(SHACL.ConstraintComponent, 
m))
                   .addProperty(asProperty(SHACL.parameter, m),
                           
m.createResource().addProperty(asProperty(SHACL.path, m), customPredicate))
                   .addProperty(asProperty(SHACL.nodeValidator, m), 
m.createResource()
                           .addProperty(RDF.type, 
asProperty(SHACL.SPARQLSelectValidator, m))
                           .addProperty(asProperty(SHACL.prefixes, m), 
m.createResource()
                                   .addProperty(asProperty(SHACL.declare, m), 
m.createResource()
                                           
.addLiteral(asProperty(SHACL.namespace, m), RDF.getURI())
                                           .addLiteral(asProperty(SHACL.prefix, 
m), "rdf")
                                   )
                           )
                           .addLiteral(asProperty(SHACL.select, m), "" +
                                   "SELECT $this (rdf:type AS ?path) (?class as 
?value)\n" +
                                   "WHERE {\n" +
                                   "   $this   a   ?class .\n" +
                                   "   FILTER NOT EXISTS {\n" +
                                   "   ?any $custom ?class\n" +
                                   "   }\n" +
                                   "}")
                   )
           ;
   
           // a sh:SPARQLTarget
           specialTarget
                   .addProperty(RDF.type, asProperty(SHACL.SPARQLTarget, m))
                   .addProperty(asProperty(SHACL.prefixes, m), 
m.createResource()
                           .addProperty(asProperty(SHACL.declare, m), 
m.createResource()
                                   .addLiteral(asProperty(SHACL.namespace, m), 
ns)
                                   .addLiteral(asProperty(SHACL.prefix, m), 
"ex")
                           )
                   )
                   .addLiteral(asProperty(SHACL.select, m), "" +
                           "SELECT ?node\n" +
                           "WHERE {\n" +
                           "   ?node a ex:A\n" +
                           "}")
   
           ;
           return m;
       }
   
       private static Property asProperty(Node n, Model m) {
           return m.wrapAsResource(n).inModel(m).as(Property.class);
       }
   }
   
   ```
   
   dependencies:
   ```xml
           <dependency>
               <groupId>org.apache.jena</groupId>
               <artifactId>jena-arq</artifactId>
               <version>${jena.version}</version>
           </dependency>
           <dependency>
               <groupId>org.apache.jena</groupId>
               <artifactId>jena-shacl</artifactId>
               <version>${jena.version}</version>
           </dependency>
           <dependency>
               <groupId>org.junit.jupiter</groupId>
               <artifactId>junit-jupiter-api</artifactId>
               <version>${junit.version}</version>
               <scope>test</scope>
           </dependency>        
   ```
   resources:
   - 
[simple-shacl-for-test.ttl](https://github.com/apache/jena/files/8524317/simple-shacl-for-test.ttl.txt)
   - 
[JenaSHACLValidator.java](https://github.com/apache/jena/files/8524327/JenaSHACLValidator.java.txt)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to