Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cubelink shapes #1471

Merged
merged 5 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -59,14 +59,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 @@ -93,6 +116,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.0.5/shape/standalone-constraint-constraint',
// 'https://cube.link/v0.0.5/shape/datacatalog-constraint',
]"""^^code:EcmaScript
)
.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fancy! Using Readable.from is a neat trick. I have to remember that.
It's a shame it takes the first argument and not a variadic argument


<#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 <http://example.org/ObservationConstraintShape> ; # from cube.link
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, did not see that coming. Maybe it's gonna be a little nicer to merge zazuko/cube-link#107 and replace example.org

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v0.1.0 of cube-link has been published, which removes example.org

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
Loading