簡體   English   中英

SHACL:要求 sh:property 是一個 URI

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

我想知道是否有一種方法可以指定給定的sh:property應具有 URI 的值而沒有任何特定的 class。

在下面的示例 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;
    .

這應該工作:

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

是的,你是對的, sh:nodeKind必須是屬性形狀的一部分。

它仍然不起作用的原因:您定義前綴的方式。 它們不是完整的 URI,因此 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;
.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM