![](/img/trans.png)
[英]SHACL with Jena, how to get the Model after SPARQL CONSTRUCT from the shape?
[英]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.