SHACL:要求SH:财产成为URI

发布于 2025-02-07 22:29:13 字数 1057 浏览 2 评论 0原文

我想知道是否有一种方法可以指定给定的sh:属性有望在没有任何特定类的情况下具有URI的值。

在下面的示例SHACL中,属性meta:value只允许URI,尽管我不知道在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
    ];
    .

示例数据

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一笔一画续写前缘 2025-02-14 22:29:13

这应该有效:

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

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
    ];
    .
凉城 2025-02-14 22:29:13

是的,您是对的,sh:nodekind必须成为属性形状的一部分。

它仍然无法使用的原因:定义前缀的方式。它们不是完整的URIS,因此SHACL处理器添加了一些零件(也许是文件的磁盘位置取决于)。结果:形状中的meta在数据中与meta不匹配。

这起作用:

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

数据

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

Yes, you are right, the sh:nodeKind has to be part of the property shape.

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). The result: the meta in the shapes never matched the meta in the data.

This works:

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;
.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文