簡體   English   中英

SHACL 中 model“逆基數”的簡單方法?

[英]Simple way to model "inverse cardinality" in SHACL?

我們想要將具有基數的本體的 UML 圖轉換為 SHACL 形狀,以驗證我們數據中的基數是否正確。

假設我們有 Author 1 ---first author ---> 1.n Book,右邊的部分很容易為 model 為:

:AuthorShape a sh:NodeShape;
    sh:targetClass :Author;
    sh:property [sh:path :firstAuthor; sh:minCount 1].

但是現在我也想 model “另一端”,即一本書不能有超過 1 個第一作者:

:FirstAuthorCardinalityOtherEndShape a sh:NodeShape;
    sh:targetObjectsOf :firstAuthor;
    sh:property [
            sh:path [ sh:inversePath :firstAuthor ];
            sh:minCount 1;
            sh:maxCount 1
    ];                              
    sh:nodeKind sh:IRI.

然而,這看起來很復雜(8 行而不是 3 行)並且容易出錯(:firstAuthor 被提及兩次)。 有沒有更簡單的方法來 model 這個?

例如,這可能是這樣的,但 sh:inverseMinCount 不存在:

:AuthorShape a sh:NodeShape;
    sh:targetClass :Author;
    sh:property [sh:path :firstAuthor; sh:minCount 1; sh:inverseMinCount 1; sh:inverseMaxCount 1].

可以通過將屬性附加到 Book 來避免兩次提到 firstAuthor 的問題,例如

:BookShape a sh:NodeShape ;
    sh:targetClass :Book ;
    sh:property [
        sh:path [ sh:inversePath :firstAuthor ] ;
        sh:maxCount 1 ;
    ] .

(您已經擁有 AuthorShape,因此擁有 BookShape 將是一件非常自然的事情)。

在任何情況下,您都不需要 sh:minCount 1,因為 sh:targetObjectsOf 已經暗示了這一點,盡管我可以從 UML 的角度理解您為什么需要它。

而且我不認為上面的設計比前向復雜得多,假設你對 sh:inversePath 開銷沒問題,這是不可避免的。

暫無
暫無

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

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