SHACL: Require sh:property to be a URI

Viewed 47

I was wondering if there's a way to specify that a given sh:property is expected to have a value of a URI without any particular class.

In the example SHACL below, the property meta:value would only allow URIs, although I don't know of a way to represent it in SHACL.

Example SHACL

@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

@prefix meta: <metadata#> .
@prefix meta_sh: <metadata/shacl#> .

meta_sh:Entry
    a sh:NodeShape;
    sh:targetClass meta:Entry;
    sh:property [
        sh:path meta:value;
        # Value expected to be a URI
        sh:minCount 1; # Required; 1 or more
    ];
    sh:property [
        sh:path meta:time;
        sh:datatype xsd:dateTime;
        sh:minCount 1; sh:maxCount 1; # Required; 1
    ];
    .

Example Data

@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

@prefix meta: <metadata#> .
@prefix data: <data#> .

data:Entry_001
    a meta:Entry;
    meta:value data:ProductListing_459; # URI
    meta:value data:RentalListing_934; # URI
    meta:time "2022-06-15T06:20:31Z"^^xsd:dateTime;
    .
1 Answers

this should work:

@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

@prefix meta: <metadata#> .
@prefix meta_sh: <metadata/shacl#> .

meta_sh:Entry
    a sh:NodeShape;
    sh:targetClass meta:Entry;
    sh:nodeKind sh:IRI ;
    sh:property [
        sh:path meta:value;
        # Value expected to be a URI
        sh:minCount 1; # Required; 1 or more
    ];
    sh:property [
        sh:path meta:time;
        sh:datatype xsd:dateTime;
        sh:minCount 1; sh:maxCount 1; # Required; 1
    ];
    .
Related