Skip to content

Commit

Permalink
Merge pull request #1471 from zazuko/use-cubelink-shapes
Browse files Browse the repository at this point in the history
Use cubelink shapes
  • Loading branch information
tpluscode authored Nov 9, 2023
2 parents 259b48b + 2fbd704 commit 6cb536c
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 80 deletions.
5 changes: 5 additions & 0 deletions .changeset/violet-dogs-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cube-creator/cli": major
---

Use [cube.link shapes](https://github.com/zazuko/cube-link/tree/main/validation) for validation
1 change: 1 addition & 0 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"barnard59-base": "^1.1.0",
"barnard59-formats": "^1.1.0",
"barnard59-graph-store": "^1.0.0",
"barnard59-http": "^1.1.1",
"barnard59-rdf": "^1.0.0",
"barnard59-validate-shacl": "^0.3.8",
"body-parser": "^1.19.0",
Expand Down
89 changes: 88 additions & 1 deletion cli/pipelines/publish.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,37 @@
code:link <node:barnard59-validate-shacl/validate.js#shacl>
] ;
code:arguments
[ code:name "shape" ; code:value <#loadShapes> ] ,
[ code:name "shape" ; code:value <#concatShapes> ] ,
[ code:name "maxErrors" ; code:value 100 ] ,
[
code:name "onViolation" ;
code:value [ a code:EcmaScript ; code:link <file:../lib/log#prettyPrintReport> ]
] ;
.

<#concatShapes> a :Pipeline, :ReadableObjectMode ;
:steps [
:stepList
(
<#loadAllShapes>
)
].


<#loadAllShapes>
a :Step ;
code:implementedBy
[
a code:EcmaScriptModule ;
code:link <node:barnard59-base/concat.js#object>
] ;
code:arguments
(
<#loadShapes>
<#loadCubeShapes>
)
.

<#loadShapes>
a :Pipeline, :ReadableObjectMode ;
:steps
Expand All @@ -94,6 +117,70 @@
)
] .

<#loadCubeShapes>
a :Pipeline, :ReadableObjectMode ;
:steps
[
:stepList
(
<#shapeURLs>
<#getShapes>
)
] .

<#shapeURLs> a :Step ;
code:implementedBy [
a code:EcmaScriptModule ;
code:link <node:stream#Readable.from> ;
] ;
code:arguments (
"""[
'https://cube.link/v0.1.0/shape/standalone-constraint-constraint',
// 'https://cube.link/v0.1.0/shape/datacatalog-constraint',
]"""^^code:EcmaScript
)
.

<#getShapes> a :Step ;
code:implementedBy [
a code:EcmaScriptModule ;
code:link <node:barnard59-base/forEach.js#default> ;
] ;
code:arguments ( <#getShape> "shapeURL" )
.

<#getShape> a :Pipeline , :ReadableObjectMode;
:steps
[
:stepList
(
<#fetch>
<#parse>
)
] .

<#fetch> a :Step ;
code:implementedBy
[
a code:EcmaScriptModule ;
code:link <node:barnard59-http/get.js#default>
] ;
code:arguments
[
code:name "url";
code:value "shapeURL"^^:VariableName ;
]
.

<#parse> a :Step ;
code:implementedBy
[
code:link <node:barnard59-formats/n3.js#parse> ;
a code:EcmaScriptModule ;
]
.


<#flatten> a :Step ;
code:implementedBy
[
Expand Down
80 changes: 1 addition & 79 deletions cli/shapes.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ base <https://cube-creator.zazuko.com/shape#>
sh:message "cube:Cube needs at least one cube:ObservationSet" ;
] , [
sh:path cube:observationConstraint ;
sh:node <ObservationConstraintShape> ;
sh:node <https://cube.link/shape/standalone-constraint-constraint#ObservationConstraintShape> ; # from cube.link
sh:message "cube:Cube must point to a valid cube:Constraint" ;
] ;
.
Expand Down Expand Up @@ -60,84 +60,6 @@ base <https://cube-creator.zazuko.com/shape#>
] ;
.

<ObservationConstraintShape>
a sh:NodeShape ;
sh:property [
# we assume at least 3 dimensions, otherwise we would have an empty list of dimensions
# one for cube:observedBy, one for rdf:type and at least one cube dimension
sh:path sh:property ;
sh:minCount 3 ;
sh:message "cube:Constraint needs at least {$minCount} sh:properties" ;
] , [
sh:path sh:property ;
sh:node <ObservationConstraintProperty> ;
] , [
sh:path sh:closed ;
sh:hasValue true ;
] ;
.

<ObservationConstraintProperty> a sh:NodeShape;
sh:property [
sh:path qudt:scaleType ;
sh:in ( qudt:IntervalScale qudt:NominalScale qudt:EnumerationScale qudt:RatioScale qudt:OrdinalScale) ;
sh:message "If qudt:scale is used it needs to be within" ;
] , [
sh:path sh:path ;
sh:minCount 1 ;
sh:maxCount 1 ;
sh:message "a sh:path is needed on a property" ;
] , [
sh:path sh:in ;
sh:node <listnode> ;
sh:message "sh:in needs to be a list" ;
] , [
sh:message "needs a schema:name" ;
sh:or (
[
sh:path schema:name ;
sh:minCount 1 ;
sh:datatype xsd:string ;
]
[
sh:path schema:name ;
sh:minCount 1 ;
sh:datatype rdf:langString ;
]
[
sh:path sh:path ;
sh:in (rdf:type cube:observedBy) ;
]
) ;
] , [
sh:message "needs a sh:datatype or sh:nodeKind" ;
sh:or (
[
sh:path sh:datatype ;
sh:minCount 1 ;
]
[
sh:path sh:nodeKind ;
sh:minCount 1 ;
]
) ;
] ;
.

# Testing proper rdf:list construction
<listnode> a sh:NodeShape ;
sh:property [
sh:path rdf:first ;
sh:minCount 1 ;
sh:maxCount 1 ;
] , [
sh:path rdf:rest ;
sh:minCount 1 ;
sh:maxCount 1 ;
sh:message "a rdf:List can only have one rdf:rest node, multiples nodes need to be linked" ;
#sh:node <restnode>;
] ;
.

<NoMdHierarchy>
a sh:NodeShape ;
Expand Down

0 comments on commit 6cb536c

Please sign in to comment.