Skip to content

Commit 9e07dc3

Browse files
committed
Fix #224
1 parent b6814a5 commit 9e07dc3

File tree

7 files changed

+51
-45
lines changed

7 files changed

+51
-45
lines changed

shacl-play-app/src/main/java/fr/sparna/rdf/shacl/app/validate/Validate.java

+5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public void execute(Object args) throws Exception {
6161
ShaclValidator validator = new ShaclValidator(shapesModel, extraModel);
6262
validator.setCreateDetails(a.isCreateDetails());
6363
validator.setProgressMonitor(new Slf4jProgressMonitor("SHACL validator", log));
64+
65+
// we are asking for the extra gathering of focus nodes and the validation of
66+
// whether shapes matched focus nodes and whether all nodes were targeted by at least a shape
67+
validator.setResolveFocusNodes(true);
68+
6469
Model validationResults = validator.validate(dataModel);
6570

6671
// union results and shapes

shacl-printer/src/main/java/fr/sparna/rdf/shacl/printer/report/ValidationReport.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,11 @@ public long getNumberOfOthers() {
134134

135135
/**
136136
* We don't refer to constants in order not to introduce a dependency to the validation module
137-
* @return
137+
* @return list of shapes flagged with shp:targetMatched false
138+
* @deprecated this is not used anymore since now the validation report contains this as true validation results
138139
*/
139140
public List<Resource> getShapesWithNoMatch() {
140-
List<Statement> targetMatchedFalseStatements = this.fullModel.listStatements(null, this.fullModel.createProperty("http://shacl-play.sparna.fr/ontology#targetMatched"), this.fullModel.createTypedLiteral(false)).toList();
141+
List<Statement> targetMatchedFalseStatements = this.fullModel.listStatements(null, this.fullModel.createProperty("https://shacl-play.sparna.fr/ontology#targetMatched"), this.fullModel.createTypedLiteral(false)).toList();
141142
return targetMatchedFalseStatements.stream().map(s -> s.getSubject()).collect(Collectors.toList());
142143
}
143144

@@ -151,7 +152,7 @@ public boolean isConformant() {
151152
*/
152153
public boolean hasMatched() {
153154
// if not explicitely false, consider it true
154-
return !this.fullModel.containsLiteral(null, this.fullModel.createProperty("http://shacl-play.sparna.fr/ontology#hasMatched"), false);
155+
return !this.fullModel.containsLiteral(null, this.fullModel.createProperty("https://shacl-play.sparna.fr/ontology#hasMatched"), false);
155156
}
156157

157158
public Model getResultsModel() {

shacl-printer/src/main/resources/templates/ReportTitle.ftlh

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
<#macro reportTitle hasMatched violations warnings infos others>
22

3-
<#if violations &gt; 0>
4-
${ violations } Violation<#if violations &gt; 1>s</#if>
5-
<#if (warnings &gt; 0 || infos &gt; 0 || others &gt; 0)>,</#if>
6-
</#if>
7-
<#if warnings &gt; 0>
8-
${ warnings } Warning<#if warnings &gt; 1>s</#if>
9-
<#if (infos &gt; 0 || others &gt; 0)>,</#if>
10-
</#if>
11-
<#if infos &gt; 0>
12-
${ infos } Info<#if infos &gt; 1>s</#if>
13-
<#if (others &gt; 0)>,</#if>
14-
</#if>
15-
<#if others &gt; 0>
16-
${ others } Other<#if others&gt; 1>s</#if>
17-
</#if>
18-
19-
<#if violations == 0 && warnings == 0 && infos == 0 && others == 0>
20-
<#if hasMatched>
3+
<#if !hasMatched>
4+
<span class="badge badge-pill badge-secondary">No Match</span>&nbsp;Shapes did not match anything !
5+
<#else>
6+
<#if violations == 0 && warnings == 0 && infos == 0 && others == 0>
217
<span class="badge badge-pill badge-success">Valid</span>&nbsp;Data is conformant !
228
<#else>
23-
<span class="badge badge-pill badge-secondary">No Match</span>&nbsp;Shapes did not match anything !
9+
<#if violations &gt; 0>
10+
${ violations } Violation<#if violations &gt; 1>s</#if>
11+
<#if (warnings &gt; 0 || infos &gt; 0 || others &gt; 0)>,</#if>
12+
</#if>
13+
<#if warnings &gt; 0>
14+
${ warnings } Warning<#if warnings &gt; 1>s</#if>
15+
<#if (infos &gt; 0 || others &gt; 0)>,</#if>
16+
</#if>
17+
<#if infos &gt; 0>
18+
${ infos } Info<#if infos &gt; 1>s</#if>
19+
<#if (others &gt; 0)>,</#if>
20+
</#if>
21+
<#if others &gt; 0>
22+
${ others } Other<#if others&gt; 1>s</#if>
23+
</#if>
2424
</#if>
2525
</#if>
2626

shacl-printer/src/main/resources/templates/ValidationReportHtmlWriter.ftlh

-9
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,6 @@
3131
others=report.validationReport.numberOfOthers
3232
/>
3333
</h3>
34-
<#if report.validationReport.hasMatched() && report.validationReport.shapesWithNoMatch?size &gt; 0>
35-
<small>Warning, following shapes did not match anything :
36-
<ul>
37-
<#list report.validationReport.shapesWithNoMatch as aShapeWithNoMatch>
38-
<li>${aShapeWithNoMatch}</li>
39-
</#list>
40-
</ul>
41-
</small>
42-
</#if>
4334
</div>
4435
<div class="card-body">
4536
<ul style="list-style-type: none;">

shacl-validator/src/main/java/fr/sparna/rdf/shacl/validator/ShaclValidator.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.topbraid.shacl.vocabulary.SH;
3333
import org.topbraid.shacl.vocabulary.TOSH;
3434

35+
import fr.sparna.rdf.shacl.targets.AddHasTargetListener;
3536
import fr.sparna.rdf.shacl.targets.ShapeFocusNodesResolver;
3637
import fr.sparna.rdf.shacl.targets.StoreHasFocusNodeListener;
3738

@@ -196,7 +197,7 @@ public void resolveFocusNodes(Model dataModel, Model existingValidationReport) t
196197
targetResolver.getListeners().add(new StoreHasFocusNodeListener(existingValidationReport));
197198
targetResolver.getListeners().add(new StoreHasFocusNodeListener(dataModel));
198199

199-
// targetResolver.getListeners().add(new AddHasTargetListener(existingValidationReport));
200+
targetResolver.getListeners().add(new AddHasTargetListener(existingValidationReport));
200201
// targetResolver.getListeners().add(new AddNotTargetOfAnyShapeListener(dataModel, existingValidationReport));
201202

202203
targetResolver.resolveFocusNodes();

shacl-validator/src/main/resources/closed-graph-shapes.ttl

+10-6
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ shpshapes:ClosedGraphShape a sh:NodeShape ;
1111
sh:select "SELECT $this WHERE { $this ?p ?o FILTER(?p != <https://shacl-play.sparna.fr/ontology#hasFocusNode>) }";
1212
] ;
1313
# every triple subject must be matched by at least one shape
14-
sh:property [
15-
sh:path [ sh:inversePath shp:hasFocusNode ] ;
16-
sh:minCount 1 ;
17-
sh:message "Node was not matched by any shape" ;
18-
sh:severity sh:Warning ;
19-
] ;
14+
sh:property shpshapes:hasInverseFocusNodeMandatory ;
15+
.
16+
17+
shpshapes:hasInverseFocusNodeMandatory
18+
sh:path [ sh:inversePath shp:hasFocusNode ] ;
19+
sh:minCount 1 ;
20+
sh:message "Subject of a triple was not validated by any shape"@en ;
21+
# comment otherwise we get 2 messages in the output
22+
# sh:message "Le sujet d'un triplet n'a été validé par aucune shape"@fr ;
23+
sh:severity sh:Warning ;
2024
.

shacl-validator/src/main/resources/shapes-coverage-shapes.ttl

+11-7
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ shpshapes:AtLeastOneFocusNodeShape a sh:NodeShape ;
1414
sh:target [
1515
sh:select "SELECT $this WHERE { $this a <http://www.w3.org/ns/shacl#NodeShape> ; a <http://www.w3.org/2002/07/owl#Class> }"
1616
] ;
17-
# every shape that has a target definition must have matched at least one focus node
18-
sh:property [
19-
sh:path shp:hasFocusNode ;
20-
sh:minCount 1 ;
21-
sh:message "Shape did not match any node in the data" ;
22-
sh:severity sh:Warning ;
23-
]
17+
sh:property shpshapes:hasFocusNodeMandatory
18+
.
19+
20+
# every shape that has a target definition must have matched at least one focus node
21+
shpshapes:hasFocusNodeMandatory
22+
sh:path shp:hasFocusNode ;
23+
sh:minCount 1 ;
24+
sh:message "Shape did not validate any node in the data"@en ;
25+
# comment otherwise we get 2 messages in the output
26+
# sh:message "La shape n'a validé aucune ressource dans les données"@fr ;
27+
sh:severity sh:Warning ;
2428
.

0 commit comments

Comments
 (0)