You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by gi...@apache.org on 2022/08/25 09:17:59 UTC

[jena-site] branch asf-site updated: Updated site from main (74d2d8fbcf32b0a999433cf643b3fc28f955b065)

This is an automated email from the ASF dual-hosted git repository.

git-site-role pushed a commit to branch asf-site
in repository https://gitbox.apache.org/repos/asf/jena-site.git


The following commit(s) were added to refs/heads/asf-site by this push:
     new 3fa10e857 Updated site from main (74d2d8fbcf32b0a999433cf643b3fc28f955b065)
3fa10e857 is described below

commit 3fa10e8577126ead1d87a73efacae11df588ca1e
Author: jenkins <bu...@apache.org>
AuthorDate: Thu Aug 25 09:17:54 2022 +0000

    Updated site from main (74d2d8fbcf32b0a999433cf643b3fc28f955b065)
---
 content/documentation/shacl/index.html | 56 ++++++++++++++++++++++++++++++++++
 content/sitemap.xml                    |  4 +--
 2 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/content/documentation/shacl/index.html b/content/documentation/shacl/index.html
index 19a6b0650..8ad37ad9b 100644
--- a/content/documentation/shacl/index.html
+++ b/content/documentation/shacl/index.html
@@ -305,6 +305,62 @@ for details.</p>
             }
             &quot;&quot;&quot; ;
     ] ;
+</code></pre><h2 id="validationlistener">ValidationListener</h2>
+<p>When given a <code>ValidationListener</code> the SHACL validation code emits events at each step of validation:</p>
+<ul>
+<li>when validation of a shape starts or finishes</li>
+<li>when the focus nodes of the shape have been identified</li>
+<li>when validation of a constraint begins, ends and yields positive or negative results</li>
+</ul>
+<p>For example, the following listener will just record all events in a List:</p>
+<pre><code>public class RecordingValidationListener implements ValidationListener {
+        private final List&lt;ValidationEvent&gt; events = new ArrayList&lt;&gt;();
+
+        @Override public void onValidationEvent(ValidationEvent e) {
+            events.add(e);
+        }
+
+        public List&lt;ValidationEvent&gt; getEvents() {
+            return events;
+        }
+    }
+</code></pre><p>The listener must be passed to the constructor of the <code>ValidationContext</code>.
+The following example validates the <code>dataGraph</code> according to the <code>shapesGraph</code> using the ValidationListener above:</p>
+<pre><code>    Graph shapesGraph = RDFDataMgr.loadGraph(shapesGraphUri); //assuming shapesGraphUri points to an RDF file
+    Graph dataGraph = RDFDataMgr.loadGraph(dataGraphUri); //assuming dataGraphUri points to an RDF file
+    RecordingValidationListener listener = new RecordingValidationListener();  // see above
+    Shapes shapes = Shapes.parse(shapesGraph);
+    ValidationContext vCtx = ValidationContext.create(shapes, dataGraph, listener); // pass listener here
+    for (Shape shape : shapes.getTargetShapes()) {
+        Collection&lt;Node&gt; focusNodes = VLib.focusNodes(dataGraph, shape);
+        for (Node focusNode : focusNodes) {
+            VLib.validateShape(vCtx, dataGraph, shape, focusNode);
+        }
+    }
+    List&lt;ValidationEvent&gt; actualEvents = listener.getEvents(); // all events have been recorded
+</code></pre><p>The events thus generated might look like this (<code>event.toString()</code>, one per line):</p>
+<pre><code> FocusNodeValidationStartedEvent{focusNode=http://datashapes.org/sh/tests/core/node/class-001.test#Someone, shape=NodeShape[http://datashapes.org/sh/tests/core/node/class-001.test#TestShape]}
+ ConstraintEvaluationForNodeShapeStartedEvent{constraint=ClassConstraint[&lt;http://datashapes.org/sh/tests/core/node/class-001.test#Person&gt;], focusNode=http://datashapes.org/sh/tests/core/node/class-001.test#Someone, shape=NodeShape[http://datashapes.org/sh/tests/core/node/class-001.test#TestShape]}
+ ConstraintEvaluatedOnFocusNodeEvent{constraint=ClassConstraint[&lt;http://datashapes.org/sh/tests/core/node/class-001.test#Person&gt;], focusNode=http://datashapes.org/sh/tests/core/node/class-001.test#Someone, shape=NodeShape[http://datashapes.org/sh/tests/core/node/class-001.test#TestShape], valid=true}
+ ConstraintEvaluationForNodeShapeFinishedEvent{constraint=ClassConstraint[&lt;http://datashapes.org/sh/tests/core/node/class-001.test#Person&gt;], focusNode=http://datashapes.org/sh/tests/core/node/class-001.test#Someone, shape=NodeShape[http://datashapes.org/sh/tests/core/node/class-001.test#TestShape]}
+ FocusNodeValidationFinishedEvent{focusNode=http://datashapes.org/sh/tests/core/node/class-001.test#Someone, shape=NodeShape[http://datashapes.org/sh/tests/core/node/class-001.test#TestShape]}
+[...]    
+</code></pre><p>Many use cases can be addressed with the <code>HandlerBasedValidationListener</code>, which allows for registering event handlers on a per-event basis.
+For example:</p>
+<pre><code>    ValidationListener myListener = HandlerBasedValidationListener
+        .builder()
+        .forEventType(FocusNodeValidationStartedEvent.class)
+        .addSimpleHandler(e -&gt; {
+           // ... 
+        })
+        .forEventType(ConstraintEvaluatedEvent.class)
+        .addHandler(c -&gt; c
+            .iff(EventPredicates.isValid()) // use a Predicate&lt;ValidationEvent&gt; to select events
+            .handle(e -&gt; {
+                // ...
+            })
+        )
+        .build();
 </code></pre>
 
         </div>
diff --git a/content/sitemap.xml b/content/sitemap.xml
index 93c9e8522..7daa2c895 100644
--- a/content/sitemap.xml
+++ b/content/sitemap.xml
@@ -94,7 +94,7 @@
   
   <url>
     <loc>https://jena.apache.org/documentation/shacl/</loc>
-    <lastmod>2022-01-21T10:23:11+00:00</lastmod>
+    <lastmod>2022-08-25T11:16:35+02:00</lastmod>
   </url>
   
   <url>
@@ -329,7 +329,7 @@
   
   <url>
     <loc>https://jena.apache.org/documentation.html</loc>
-    <lastmod>2022-08-25T11:16:14+02:00</lastmod>
+    <lastmod>2022-08-25T11:16:35+02:00</lastmod>
   </url>
   
   <url>