kinow commented on a change in pull request #586: JENA-1733: SHACL engine, 
command line validator and Fuseki service.
URL: https://github.com/apache/jena/pull/586#discussion_r306691526
 
 

 ##########
 File path: jena-shacl/src/main/java/org/apache/jena/shacl/ValidationReport.java
 ##########
 @@ -0,0 +1,209 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.shacl;
+
+import java.util.*;
+
+import org.apache.jena.graph.Graph;
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.NodeFactory;
+import org.apache.jena.graph.Triple;
+import org.apache.jena.rdf.model.Model;
+import org.apache.jena.rdf.model.ModelFactory;
+import org.apache.jena.rdf.model.Resource;
+import org.apache.jena.shacl.engine.ShaclPaths;
+import org.apache.jena.shacl.engine.exec.TripleValidator;
+import org.apache.jena.shacl.lib.G;
+import org.apache.jena.shacl.parser.Constraint;
+import org.apache.jena.shacl.parser.Shape;
+import org.apache.jena.shacl.sys.C;
+import org.apache.jena.shacl.validation.ReportEntry;
+import org.apache.jena.shacl.validation.ReportItem;
+import org.apache.jena.shacl.vocabulary.SHACL;
+import org.apache.jena.shacl.vocabulary.SHACLM;
+import org.apache.jena.sparql.path.Path;
+import org.apache.jena.vocabulary.RDF;
+import org.apache.jena.vocabulary.RDFS;
+import org.apache.jena.vocabulary.XSD;
+
+public class ValidationReport {
+
+    private static ValidationReport singletonReportConformsTrue = new 
ValidationReport(Collections.emptySet(), Collections.emptyList());
+    private final Collection<ReportEntry> entries;
+    private final Resource resultResource;
+
+    public static Builder create() {
+        return new Builder();
+    }
+
+    /** Return an immutable report that records no validation errors 
(violations or any other level of severity) */
+    public static ValidationReport reportConformsTrue() {
+        return singletonReportConformsTrue;
+    }
+
+    private ValidationReport(Set<Triple> paths, Collection<ReportEntry> 
entries) {
+        this(entries, generate(paths, entries));
+    }
+
+    private ValidationReport(Collection<ReportEntry> entries, Resource 
resultResource) {
+        this.entries = entries;
+        this.resultResource = resultResource;
+    }
+
+    public Collection<ReportEntry> getEntries() { return entries; }
+
+    public Resource getResource() { return resultResource; }
+
+    public Model getModel() { return resultResource.getModel(); }
+
+    public Graph getGraph() {
+        return getModel().getGraph();
+    }
+
+    public boolean conforms() { return entries.isEmpty(); }
+
+    //  [   a sh:ValidationReport ;
+    //      sh:conforms true ;
+    //  ] .
+    private static Resource reportConformsTrueResource() {
+        Model model = ModelFactory.createDefaultModel();
+        model.setNsPrefix("rdf", RDF.getURI());
+        model.setNsPrefix("rdfs", RDFS.getURI());
+        model.setNsPrefix("xsd", XSD.getURI());
+        model.setNsPrefix("sh", SHACLM.getURI());
+        Resource report = model.createResource(SHACLM.ValidationReport);
+        report.addProperty(SHACLM.conforms, C.mTRUE);
+        return report;
+    }
+
+    private static Resource generate(Set<Triple> paths, 
Collection<ReportEntry> entries) {
+        if ( entries.isEmpty() )
+            return reportConformsTrueResource();
+        Model model = ModelFactory.createDefaultModel();
+        model.setNsPrefix("rdf", RDF.getURI());
+        model.setNsPrefix("rdfs", RDFS.getURI());
+        model.setNsPrefix("sh", SHACLM.getURI());
+        Resource report = model.createResource(SHACLM.ValidationReport);
+        entries.forEach(e->e.generate(model, report));
+        paths.forEach(model.getGraph()::add);
+        report.addProperty(SHACLM.conforms, C.mFALSE);
+        return report;
+    }
+
+    public static ValidationReport fromGraph(Graph graph, Node node) {
+        //RDFDataMgr.write(System.err,  graph, Lang.TTL);
+
+        boolean conforms = G.contains(graph, node, SHACL.conforms, C.TRUE);
+        List<Node> results = G.listSP(graph, node, SHACL.result);
+        if ( conforms && ! results.isEmpty() ) {}
 
 Review comment:
   debug/unused code?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to