Skip to content

Commit

Permalink
use a copy of cube.link shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomociti committed Oct 16, 2023
1 parent 9dc96c7 commit cda8bcc
Show file tree
Hide file tree
Showing 4 changed files with 269 additions and 80 deletions.
1 change: 1 addition & 0 deletions cli/lib/commands/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default runner.create<PublishRunOptions>({
variable.set('metadata', $rdf.dataset())
// this should be possible as relative path in pipeline ttl but does not work
variable.set('shapesPath', path.resolve(__dirname, '../../shapes.ttl'))
variable.set('cubeShapesPath', path.resolve(__dirname, '../../standalone-constraint-constraint.ttl'))

if (cubeCreatorVersion) {
variable.set('cubeCreatorVersion', cubeCreatorVersion)
Expand Down
51 changes: 50 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,32 @@
)
] .

<#loadCubeShapes>
a :Pipeline, :ReadableObjectMode ;
:steps
[
:stepList
(
[
a :Step ;
code:implementedBy
[
code:link <node:fs#createReadStream> ;
a code:EcmaScriptModule ;
] ;
code:arguments ( "cubeShapesPath"^^:VariableName )
]
[
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
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
217 changes: 217 additions & 0 deletions cli/standalone-constraint-constraint.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
@base <http://example.org/> .
@prefix dash: <http://datashapes.org/dash#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <http://schema.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix cube: <https://cube.link/> .
@prefix meta: <https://cube.link/meta/> .
@prefix qudt: <http://qudt.org/schema/qudt/> .

#
# This is the bare minimal SHACL shape for validating a Cube Constraint.
# All Cube Constraints should pass this validation.
#

<ObservationConstraintShape>
a sh:NodeShape ;
sh:targetClass cube:Constraint ;
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 a certain amount of sh:properties"
] ;
sh:property [
sh:path sh:property ;
sh:node <ObservationConstraintProperty>;
sh:message "The constraints do not validate"
] ;
sh:property [
sh:path sh:closed;
sh:hasValue true;
] ;
sh:property [
sh:path meta:inHierarchy;
sh:node <Hierarchy>;
sh:message "meta:inHierarchy does not validate"
] ;
.

<ObservationConstraintProperty> a sh:NodeShape;
sh:property [
sh:path qudt:scaleType;
sh:in ( qudt:IntervalScale qudt:NominalScale qudt:EnumerationScale qudt:RatioScale qudt:OrdinalScale) ;
sh:maxCount 1;
sh:message "If qudt:scaleType is used it needs to be within ( qudt:IntervalScale qudt:NominalScale qudt:EnumerationScale qudt:RatioScale qudt:OrdinalScale )"
];
sh:property [
sh:path sh:path;
sh:minCount 1;
sh:maxCount 1;
sh:message "a sh:path is needed on a property"
];
sh:property [
sh:path sh:minInclusive;
sh:nodeType sh:Literal;
sh:message "sh:minInclusive needs to be a literal"
];
sh:property [
sh:path sh:in;
sh:node <listnode>;
sh:message "sh:in needs to be a list"
];
sh:property [
sh:path sh:maxInclusive;
sh:nodeType sh:Literal;
sh:message "sh:maxInclusive needs to be a literal"
];
sh:property [
sh:path meta:dimensionRelation;
sh:node <DimensionRelation>;
sh:message "meta:dimensionRelation does not validate"
];

sh:property [
sh:message "needs a schema:name" ;
sh:or(
[
sh:path schema:name;
sh:minCount 1;
sh:or ( [ sh:datatype xsd:string ] [ sh:datatype rdf:langString ] ) ;
]
[
sh:path sh:path;
sh:in (rdf:type cube:observedBy);
]
);
];

sh:property [
sh:message "needs a sh:datatype, sh:nodeKind or sh:datatype within sh:or (...)" ;
sh:or(
[
sh:path sh:datatype;
sh:minCount 1;
]
[
sh:path sh:nodeKind;
sh:minCount 1;
]
[
sh:path sh:or;
sh:minCount 1;
sh:node <listnode> ;
sh:node [
sh:path ( [ sh:zeroOrMorePath rdf:rest ] rdf:first ) ; # all list elements
sh:property [ sh:path sh:datatype ; sh:minCount 1 ] ; # have at least one datatype
]
]
);
] ;

.


<DimensionRelation> a sh:NodeShape ;
sh:property [
sh:path meta:relatesTo;
sh:nodeKind sh:IRI ;
sh:minCount 1;
sh:message "meta:dimensionRelation requires at least one meta:relatesTo";
] .


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

<inversepathnode> a sh:NodeShape ;
sh:property [
sh:path sh:inversePath;
sh:nodeKind sh:IRI;
sh:minCount 1;
sh:maxCount 1;
sh:message "nextInHierarchy requires sh:path to be IRI or [ sh:inversePath ... ]"
] .

<NextInHierarchy> a sh:NodeShape ;
sh:property [
sh:path sh:path;
sh:minCount 1;
sh:maxCount 1;
sh:message "nextInHierarchy requires exactly one sh:path"
],
[
sh:path schema:name;
sh:minCount 1;
sh:message "nextInHierarchy requires schema:name"
],
[
sh:path sh:targetClass;
sh:nodeKind sh:IRI;
sh:message "meta:nextInHierarchy/sh:targetClass must be an IRI"
],
[
sh:path meta:nextInHierarchy;
sh:node <NextInHierarchy> ;
sh:severity sh:Info;
sh:message "nextInHierarchy can have nested nodes"
] ;
sh:or (
[
sh:path sh:path;
sh:nodeKind sh:IRI;
sh:message "nextInHierarchy requires sh:path to be IRI or [ sh:inversePath ... ]"
]
[
sh:path sh:path;
sh:nodeKind sh:BlankNode;
sh:node <inversepathnode>;
sh:message "nextInHierarchy requires sh:path to be IRI or [ sh:inversePath ... ]"
]
)
.

<Hierarchy> a sh:NodeShape ;
sh:targetClass meta:Hierarchy ;
sh:property [
sh:path meta:hierarchyRoot;
sh:minCount 1;
sh:nodeKind sh:IRI;
sh:message "inHierarchy requires hierarchyRoot";
],
[
sh:path schema:name;
sh:minCount 1;
sh:message "inHierarchy requires schema:name"
],
[
sh:path meta:nextInHierarchy;
sh:node <NextInHierarchy>;
sh:minCount 1;
sh:message "inHierarchy requires a conform nextInHierarchy"
] .

0 comments on commit cda8bcc

Please sign in to comment.