简体   繁体   English

SHACL 中 model“逆基数”的简单方法?

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

We want to transform a UML diagram of an ontology with cardinalities into a SHACL shape to validate if the cardinalities in our data are correct.我们想要将具有基数的本体的 UML 图转换为 SHACL 形状,以验证我们数据中的基数是否正确。

Let's say we have Author 1 ---first author ---> 1.n Book, the right part is quite easy to model as:假设我们有 Author 1 ---first author ---> 1.n Book,右边的部分很容易为 model 为:

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

However now I also want to model the "other end", ie that a book cannot have more than 1 first authors:但是现在我也想 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.

However that looks quite convoluted (8 lines instead of 3) and error prone (:firstAuthor is mentioned twice).然而,这看起来很复杂(8 行而不是 3 行)并且容易出错(:firstAuthor 被提及两次)。 Is there a simpler way to model this?有没有更简单的方法来 model 这个?

For example, this could be like this, but sh:inverseMinCount doesn't exist:例如,这可能是这样的,但 sh:inverseMinCount 不存在:

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

The issue that:firstAuthor is mentioned twice can be avoided by attaching the property to Book, eg可以通过将属性附加到 Book 来避免两次提到 firstAuthor 的问题,例如

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

(You already have AuthorShape, so having BookShape would be a perfectly natural thing to do). (您已经拥有 AuthorShape,因此拥有 BookShape 将是一件非常自然的事情)。

In any case you wouldn't need the sh:minCount 1 because the sh:targetObjectsOf already implies this, although I can see why you would want this from an UML point of view.在任何情况下,您都不需要 sh:minCount 1,因为 sh:targetObjectsOf 已经暗示了这一点,尽管我可以从 UML 的角度理解您为什么需要它。

And I don't think the design above is much more complex than the forward direction, assuming you're OK with the sh:inversePath overhead, which is unavoidable.而且我不认为上面的设计比前向复杂得多,假设你对 sh:inversePath 开销没问题,这是不可避免的。

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

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