Skip to content

Commit

Permalink
refactor: use SPARQL to adjust valid query so that it becomes invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Dec 1, 2023
1 parent 5eead14 commit 3b48c38
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 77 deletions.
10 changes: 10 additions & 0 deletions test/opendata.swiss/invalid-missing-identifier.cube.rq
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
PREFIX dcterms: <http://purl.org/dc/terms/>

CONSTRUCT {
?s ?p ?o
} WHERE {
?s ?p ?o .
MINUS {
?s dcterms:identifier ?o .
}
}
30 changes: 0 additions & 30 deletions test/opendata.swiss/invalid-missing-identifier.cube.ttl

This file was deleted.

15 changes: 11 additions & 4 deletions test/profiles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ SCRIPT_PATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
FAILED=0

function reportFailure() {
message=$3
if [ -z "$message" ]; then
message="compare reports"
fi

playground=$("$SCRIPT_PATH"/shorten-report.js "$1" "$2")
echo "❌ FAIL - check report on $playground"
echo "❌ FAIL - $message: $playground"
}

# iterate over valid cases, run validation and monitor exit code
Expand All @@ -23,12 +28,14 @@ for file in "$SCRIPT_PATH"/*/valid*.ttl; do
done

# iterate over invalid cases
for file in "$SCRIPT_PATH"/*/invalid*.cube.ttl; do
for file in "$SCRIPT_PATH"/*/invalid*.cube.rq; do
echo "Test case $file"
report=$(npx barnard59 cube check-metadata --profile validation/profile-opendataswiss.ttl < "$file" 2> /dev/null)
expectation="${file/cube\.ttl/expectation.ttl}"
invalidCube=$(arq --data "$SCRIPT_PATH"/opendata.swiss/valid.ttl --query "$file" 2> /dev/null)
report=$(echo "$invalidCube" | npx barnard59 cube check-metadata --profile validation/profile-opendataswiss.ttl 2> /dev/null)
expectation="${file/cube\.rq/expectation.ttl}"
if ! echo "$report" | npx barnard59 shacl validate --shapes "$expectation" > /dev/null 2>&1; then
reportFailure "$(cat "$expectation")" "$report"
reportFailure "$(cat validation/profile-opendataswiss.ttl)" "$invalidCube" "actual validation"
FAILED=1
fi
done
Expand Down
178 changes: 178 additions & 0 deletions validation/profile-opendataswiss-lindas.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX dcat: <http://www.w3.org/ns/dcat#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX schema: <http://schema.org/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX sh: <http://www.w3.org/ns/shacl#>
prefix code: <https://cube.link/code#>
prefix dcat-theme: <http://dcat-ap.ch/vocabulary/themes/>
prefix cube: <https://cube.link/>
prefix frequency: <http://publications.europa.eu/resource/authority/frequency/>
prefix : <https://cube.link/>

[
code:imports <./standalone-cube-constraint>
] .

<CubeShape>
a sh:NodeShape ;
sh:targetClass cube:Cube ;
sh:property
[
sh:path rdf:type ;
sh:hasValue dcat:Dataset ;
],
[
sh:path dcterms:creator ;
sh:equals schema:creator ;
],
[
sh:path dcterms:publisher ;
sh:equals schema:publisher ;
],
[
sh:path dcat:contactPoint ;
sh:equals schema:contactPoint ;
],
[
sh:path dcterms:identifier ;
sh:minCount 1 ;
sh:maxCount 1 ;
sh:datatype xsd:string ;
],
[
sh:path schema:workExample ;
sh:hasValue <https://ld.admin.ch/application/opendataswiss> ;
],
[
sh:path schema:creativeWorkStatus ;
sh:hasValue <https://ld.admin.ch/vocabulary/CreativeWorkStatus/Published> ;
],
[
sh:path dcterms:title ;
sh:minCount 1 ;
sh:languageIn ( "de" "fr" "it" "en" ) ;
sh:uniqueLang true ;
],
[
sh:path dcterms:description ;
sh:minCount 1 ;
sh:languageIn ( "de" "fr" "it" "en" ) ;
sh:uniqueLang true ;
],
[
sh:path dcat:contactPoint ;
sh:minCount 1 ;
# TODO: validate vcard structure
],
[
sh:path dcat:distribution ;
# TODO: validate structure
],
[
sh:path dcat:issued ;
sh:maxCount 1 ;
sh:datatype xsd:dateTime ;
],
[
sh:path dcat:modified ;
sh:maxCount 1 ;
sh:datatype xsd:dateTime ;
],
[
sh:path dcat:theme ;
sh:in
(
dcat-theme:work
dcat-theme:construction
dcat-theme:population
dcat-theme:education
dcat-theme:energy
dcat-theme:finances
dcat-theme:geography
dcat-theme:legislation
dcat-theme:health
dcat-theme:trade
dcat-theme:industry
dcat-theme:crime
dcat-theme:culture
dcat-theme:agriculture
dcat-theme:mobility
dcat-theme:politics
dcat-theme:prices
dcat-theme:territory
dcat-theme:social-security
dcat-theme:statistical-basis
dcat-theme:tourism
dcat-theme:administration
dcat-theme:national-economy
) ;
],
[
sh:path dcat:landingPage ;
#sh:maxCount 1 ;
sh:nodeKind sh:IRI ;
],
[
sh:path dcterms:relation ;
sh:nodeKind sh:IRI ;
],
[
sh:path rdfs:seeAlso ;
sh:nodeKind sh:IRI ;
],
[
sh:path dcterms:spatial ;
# TODO
],
[
sh:path dcterms:coverage ;
# TODO
],
[
sh:path dcterms:temporal ;
# TODO
],
[
sh:path dcat:keyword ;
sh:languageIn ( "de" "fr" "it" "en" ) ;
],
[
sh:path dcat:accrualPeriodicity ;
sh:maxCount 1 ;
sh:in
(
frequency:ANNUAL_2
frequency:ANNUAL_3
frequency:BIENNIAL
frequency:BIMONTHLY
frequency:BIWEEKLY
frequency:CONT
frequency:DAILY
frequency:DAILY_2
frequency:IRREG
frequency:MONTHLY
frequency:MONTHLY_2
frequency:MONTHLY_3
frequency:NEVER
frequency:OP_DATPRO
frequency:QUARTERLY
frequency:TRIENNIAL
frequency:UNKNOWN
frequency:UPDATE_CONT
frequency:WEEKLY_2
frequency:WEEKLY_3
frequency:QUINQUENNIAL
frequency:DECENNIAL
frequency:HOURLY
frequency:QUADRENNIAL
frequency:BIHOURLY
frequency:TRIHOURLY
frequency:BIDECENNIAL
frequency:TRIDECENNIAL
frequency:OTHER
frequency:WEEKLY
frequency:ANNUAL
) ;
] .
79 changes: 36 additions & 43 deletions validation/profile-opendataswiss.ttl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PREFIX prefix: <http://prefix.cc/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX dcat: <http://www.w3.org/ns/dcat#>
Expand All @@ -8,27 +9,19 @@ PREFIX sh: <http://www.w3.org/ns/shacl#>
prefix code: <https://cube.link/code#>
prefix dcat-theme: <http://dcat-ap.ch/vocabulary/themes/>
prefix cube: <https://cube.link/>
base <https://cube.link/shape/profile-opendataswiss#>
prefix frequency: <http://publications.europa.eu/resource/authority/frequency/>
prefix : <https://cube.link/shape/profile-opendataswiss#>

[
code:imports <./standalone-cube-constraint>
] .

<CubeShape>
:CubeShape
a sh:NodeShape ;
sh:targetClass cube:Cube ;
sh:targetClass dcat:Dataset ;
sh:property
[
sh:path rdf:type ;
sh:hasValue dcat:Dataset ;
],
[
sh:path dcterms:creator ;
sh:equals schema:creator ;
],
[
sh:path dcterms:publisher ;
sh:equals schema:publisher ;
sh:maxCount 1 ;
sh:message "Publisher must be a foaf:Organzation DCAT-AP." ;
],
Expand Down Expand Up @@ -148,36 +141,36 @@ base <https://cube.link/shape/profile-opendataswiss#>
sh:maxCount 1 ;
sh:in
(
<http://publications.europa.eu/resource/authority/frequency/ANNUAL_2>
<http://publications.europa.eu/resource/authority/frequency/ANNUAL_3>
<http://publications.europa.eu/resource/authority/frequency/BIENNIAL>
<http://publications.europa.eu/resource/authority/frequency/BIMONTHLY>
<http://publications.europa.eu/resource/authority/frequency/BIWEEKLY>
<http://publications.europa.eu/resource/authority/frequency/CONT>
<http://publications.europa.eu/resource/authority/frequency/DAILY>
<http://publications.europa.eu/resource/authority/frequency/DAILY_2>
<http://publications.europa.eu/resource/authority/frequency/IRREG>
<http://publications.europa.eu/resource/authority/frequency/MONTHLY>
<http://publications.europa.eu/resource/authority/frequency/MONTHLY_2>
<http://publications.europa.eu/resource/authority/frequency/MONTHLY_3>
<http://publications.europa.eu/resource/authority/frequency/NEVER>
<http://publications.europa.eu/resource/authority/frequency/OP_DATPRO>
<http://publications.europa.eu/resource/authority/frequency/QUARTERLY>
<http://publications.europa.eu/resource/authority/frequency/TRIENNIAL>
<http://publications.europa.eu/resource/authority/frequency/UNKNOWN>
<http://publications.europa.eu/resource/authority/frequency/UPDATE_CONT>
<http://publications.europa.eu/resource/authority/frequency/WEEKLY_2>
<http://publications.europa.eu/resource/authority/frequency/WEEKLY_3>
<http://publications.europa.eu/resource/authority/frequency/QUINQUENNIAL>
<http://publications.europa.eu/resource/authority/frequency/DECENNIAL>
<http://publications.europa.eu/resource/authority/frequency/HOURLY>
<http://publications.europa.eu/resource/authority/frequency/QUADRENNIAL>
<http://publications.europa.eu/resource/authority/frequency/BIHOURLY>
<http://publications.europa.eu/resource/authority/frequency/TRIHOURLY>
<http://publications.europa.eu/resource/authority/frequency/BIDECENNIAL>
<http://publications.europa.eu/resource/authority/frequency/TRIDECENNIAL>
<http://publications.europa.eu/resource/authority/frequency/OTHER>
<http://publications.europa.eu/resource/authority/frequency/WEEKLY>
<http://publications.europa.eu/resource/authority/frequency/ANNUAL>
frequency:ANNUAL_2
frequency:ANNUAL_3
frequency:BIENNIAL
frequency:BIMONTHLY
frequency:BIWEEKLY
frequency:CONT
frequency:DAILY
frequency:DAILY_2
frequency:IRREG
frequency:MONTHLY
frequency:MONTHLY_2
frequency:MONTHLY_3
frequency:NEVER
frequency:OP_DATPRO
frequency:QUARTERLY
frequency:TRIENNIAL
frequency:UNKNOWN
frequency:UPDATE_CONT
frequency:WEEKLY_2
frequency:WEEKLY_3
frequency:QUINQUENNIAL
frequency:DECENNIAL
frequency:HOURLY
frequency:QUADRENNIAL
frequency:BIHOURLY
frequency:TRIHOURLY
frequency:BIDECENNIAL
frequency:TRIDECENNIAL
frequency:OTHER
frequency:WEEKLY
frequency:ANNUAL
) ;
] .

0 comments on commit 3b48c38

Please sign in to comment.