简体   繁体   English

SHACL:要求 sh:property 是一个 URI

[英]SHACL: Require sh:property to be a URI

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.我想知道是否有一种方法可以指定给定的sh:property应具有 URI 的值而没有任何特定的 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.在下面的示例 SHACL 中,属性meta:value将只允许 URI,尽管我不知道在 SHACL 中表示它的方法。

Example SHACL示例 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;
    .

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
    ];
    .

Yes, you are right, the sh:nodeKind has to be part of the property shape.是的,你是对的, sh:nodeKind必须是属性形状的一部分。

The reason why it still not worked: the way you defined the prefixes.它仍然不起作用的原因:您定义前缀的方式。 They were no full URIs so the SHACL processor added some parts (maybe the disk location of the file, depends).它们不是完整的 URI,因此 SHACL 处理器添加了一些部分(可能是文件的磁盘位置,视情况而定)。 The result: the meta in the shapes never matched the meta in the data.结果:形状中的meta与数据中的meta不匹配。

This works:这有效:

SHACL SHACL

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

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

meta_sh:Entry
    a sh:NodeShape;
    sh:targetClass meta:Entry;
    sh:property [
        sh:path meta:value;
        sh:nodeKind sh:IRI ;
        sh:minCount 1; # Required; 1 or more
    ];
.

Data数据

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

@prefix meta: <https://example.org/#> .
@prefix data: <data#> .

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

data:Entry_002
    a meta:Entry;
    meta:value "this is not an uri" ; # No Uri
    meta:time "2022-06-15T06:20:31Z"^^xsd:dateTime;
.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM