Skip to content

Commit

Permalink
post-process report for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomociti committed Oct 12, 2024
1 parent f5f4228 commit f74dd8a
Show file tree
Hide file tree
Showing 8 changed files with 290 additions and 48 deletions.
12 changes: 11 additions & 1 deletion dist/compile.n3
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,24 @@
?triple this:cbd ?y .
} .

{
?triple this:cbd ?x
}
<=
{
?x list:member ?s .
?s this:nodeKind sh:BlankNode .
?triple this:cbd ?s .
} .

{
?triple this:cbd ?x
}
<=
{
?x [] [ list:member ?s ] .
?s this:nodeKind sh:BlankNode .
?triple sh:cbd ?s .
?triple this:cbd ?s .
} .
@prefix sh: <http://www.w3.org/ns/shacl#>.
@prefix this: <http://eye-shacl#> .
Expand Down
12 changes: 11 additions & 1 deletion rules/compile/cbd.n3
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,22 @@
?triple this:cbd ?y .
} .

{
?triple this:cbd ?x
}
<=
{
?x list:member ?s .
?s this:nodeKind sh:BlankNode .
?triple this:cbd ?s .
} .

{
?triple this:cbd ?x
}
<=
{
?x [] [ list:member ?s ] .
?s this:nodeKind sh:BlankNode .
?triple sh:cbd ?s .
?triple this:cbd ?s .
} .
118 changes: 118 additions & 0 deletions test/path-split.n3
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
@prefix list: <http://www.w3.org/2000/10/swap/list#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
@prefix : <#> .

# https://w3c.github.io/data-shapes/data-shapes-test-suite/#dfn-full-compliance
# the blank node structures representing property paths via sh:resultPath must not be shared among multiple results

# create a fresh blank node for each skolem node
{
?s ?p ?skolem .
?skolem log:rawType log:SkolemIRI .
?p list:in (
sh:resultPath
sh:inversePath
sh:alternativePath
sh:zeroOrMorePath
sh:zeroOrOnePath
sh:oneOrMorePath
)
}
=>
{
?skolem :becomes [ :branch ?s ] .
} .

# create a fresh blank node for each skolem node in a list
{
?s ?p ?list .
?p list:in (sh:resultPath sh:alternativePath) .
?list list:iterate (?index ?skolem) .
?skolem log:rawType log:SkolemIRI .
}
=>
{
?skolem :becomes [ :branch ?s; :list ?list; :index ?index ]
} .

# clone lists having skolem nodes, replacing each with the corresponding blank node
{
?s ?p ?list .
?p list:in (sh:resultPath sh:alternativePath) .
?list list:member [ log:rawType log:SkolemIRI ] .
(?x {
?list list:iterate (?index []) .
(?s ?list ?index) :nonSkolemMember ?x .
} ?newList) log:collectAllIn [] .
}
=>
{
?list :becomes ?newList .
?newList :branch ?s .
} .

# clone sh:resultPath triples, replacing skolem nodes
{
?result sh:resultPath ?path .
?path :becomes ?new .
?new :branch ?result .
}
=>
{
?result sh:resultPath ?new .
} .

# clone triples with skolem subjects, replacing them
{
?skolem :becomes ?blank ; ?p ?o.
?p log:notEqualTo :becomes .
(?skolem ?o) :nonSkolem ?nonSkolem .
}
=>
{
?blank ?p ?nonSkolem
} .


## maps a node to a skolem-free version:

# using a :becomes triple, if present
{
(?branch ?x) :nonSkolem ?y .
}
<=
{
?x :becomes ?y .
?y :branch ?branch .
} .
# otherwise mapping to itself
{
(?branch ?x) :nonSkolem ?x .
}
<=
{
[] log:notIncludes { ?x :becomes [ ] }
} .


## maps a list member to a non-skolem node:

# use the blank replacement for skolem nodes
{
(?branch ?list ?index) :nonSkolemMember ?blank .
}
<=
{
(?list ?index) list:memberAt [ :becomes ?blank ] .
?blank :branch ?branch ; :list ?list ; :index ?index .
} .
# otherwise keep the list member
{
(?branch ?list ?index) :nonSkolemMember ?x .
}
<=
{
(?list ?index) list:memberAt ?x .
?x log:rawType [ log:notEqualTo log:SkolemIRI ] .
} .
75 changes: 75 additions & 0 deletions test/report-actual.n3
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix sh: <http://www.w3.org/ns/shacl#>.
@prefix list: <http://www.w3.org/2000/10/swap/list#> .

# Rules used as a query to extract the relevant information to compare SHACL validation reports.

# SHACL Test Suite definition of full compliance:
# https://w3c.github.io/data-shapes/data-shapes-test-suite/#Validate

{
?report a sh:ValidationReport ; ?p ?o .
?p list:in (sh:conforms sh:result)
}
=>
{
?report a sh:ValidationReport ; ?p ?o .
} .

{
?report sh:result ?result .
?result ?p ?o .
?p list:in (
rdf:type
sh:focusNode
# sh:resultPath
sh:resultSeverity
sh:sourceConstraint
sh:sourceConstraintComponent
sh:sourceShape
sh:value
#sh:resultMessage
)
}
=>
{
?result ?p ?o
} .


# for paths, keep only triples without skolem nodes
# (relying on path-split.n3 to clone triples with skolem nodes)

{
?s ?p ?o .
?p list:in (
sh:resultPath
sh:inversePath
# sh:alternativePath
sh:zeroOrMorePath
sh:zeroOrOnePath
sh:oneOrMorePath
) .
?s log:rawType [ log:notEqualTo log:SkolemIRI ] .
?o log:rawType [ log:notEqualTo log:SkolemIRI, rdf:List ] . # lists are handled in the next rule
}
=>
{
?s ?p ?o
} .

{
?s ?p ?o .
?p list:in (
sh:resultPath
sh:alternativePath
) .
?s log:rawType [ log:notEqualTo log:SkolemIRI ] .
?o log:rawType rdf:List .
[] log:notIncludes { ?o list:member [ log:rawType log:SkolemIRI ] }.
}
=>
{
?s ?p ?o
} .
68 changes: 68 additions & 0 deletions test/report-expected.n3
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
@prefix sh: <http://www.w3.org/ns/shacl#>.
@prefix list: <http://www.w3.org/2000/10/swap/list#> .
@prefix this: <http://eye-shacl#> .
@prefix mf: <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#> .
@prefix sht: <http://www.w3.org/ns/shacl-test#> .

# Rules used as a query to extract the relevant information to compare SHACL validation reports.

# SHACL Test Suite definition of full compliance:
# https://w3c.github.io/data-shapes/data-shapes-test-suite/#Validate

{
[] a sht:Validate ; mf:result ?result .
?result a sh:ValidationReport
}
=>
{
?result a sh:ValidationReport
} .

{
[] a sht:Validate ; mf:result [ sh:result ?result ] .
?result a sh:ValidationResult
}
=>
{
?result a sh:ValidationResult
} .


{
[] a sht:Validate ; mf:result ?result .
{?s ?p ?o} this:cbd ?result .
?p list:in (
sh:result
sh:conforms
sh:focusNode
sh:resultPath
sh:resultSeverity
sh:sourceConstraint
sh:sourceConstraintComponent
sh:sourceShape
sh:value
#sh:resultMessage
)
}
=>
{
?s ?p ?o
} .


{
[] a sht:Validate ; mf:result [ sh:result ?result ] .
?result sh:resultPath ?path .
{?s ?p ?o} this:cbd ?path .
?p list:in (
sh:inversePath
sh:alternativePath
sh:zeroOrMorePath
sh:zeroOrOnePath
sh:oneOrMorePath
)
}
=>
{
?s ?p ?o
} .
39 changes: 0 additions & 39 deletions test/report.n3

This file was deleted.

10 changes: 5 additions & 5 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ files=(
"core/node/xone-001.ttl"
"core/node/xone-duplicate.ttl"

# "core/path/path-alternative-001.ttl" ## not a real issue (path in report)
# "core/path/path-complex-001.ttl" ## not a real issue (path in report)
# "core/path/path-complex-002.ttl" ## not a real issue (path in report)
# "core/path/path-inverse-001.ttl" ## not a real issue (path in report)
# "core/path/path-oneOrMore-001.ttl" ## not a real issue (path in report)
"core/path/path-alternative-001.ttl"
"core/path/path-complex-001.ttl"
"core/path/path-complex-002.ttl"
"core/path/path-inverse-001.ttl"
"core/path/path-oneOrMore-001.ttl"
"core/path/path-sequence-001.ttl"
"core/path/path-sequence-002.ttl"
"core/path/path-sequence-duplicate-001.ttl"
Expand Down
4 changes: 2 additions & 2 deletions test/testFile.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

eye --nope --quiet --query report.n3 --turtle $1 --output test-expected.ttl
eye --nope --quiet --query report-expected.n3 ../rules/compile/cbd.n3 --turtle $1 --output test-expected.ttl
eye --nope --quiet testFile.n3 $1 --pass-only-new
eye --nope --quiet --query report.n3 test-actual.ttl --output test-actual-report.ttl
eye --nope --quiet --query report-actual.n3 path-split.n3 test-actual.ttl --output test-actual-report.ttl
eye --nope --quiet --pass check.n3 | grep 'isomorphic' | wc -l

0 comments on commit f74dd8a

Please sign in to comment.