我想了解如何处理 SHACL 规则中的多路径和存在量化。让我用一个示例本体来举例说明我的问题。
本体包括“Approve”、“Legal”、“Result”、“Man”和“Machine”类,所有类都是不相交的。它有两个属性“has-theme”和“come-from”以及以下个体:
:a rdf:type :Approve ;
:has-theme :r1,:r2 .
:r1 rdf:type :Result ;
:come-from :m1 .
:r2 rdf:type :Result ;
:come-from :m2 .
:m1 rdf:type :Man .
:m2 rdf:type :Machine .
因此:批准操作“:a”有两个主题:“:r1”和“:r2”。前者来自Man“:m1”,后者来自Machine“:m2”。
我想编写一条 SHACL 规则,声明“每个批准操作的主题中至少有一个来自男人的结果是合法的”。
我尝试过这个,不将“:a”分类为合法(但应该):
:testRule rdf:type sh:NodeShape;
sh:rule [rdf:type sh:TripleRule;
sh:condition :conditionTest;
sh:subject sh:this;
sh:predicate rdf:type;
sh:object ontology:Legal
];
sh:targetClass ontology:Approve.
:conditionTest
rdf:type sh:NodeShape;
sh:property
[
#IF the theme of the Approve action is a Result come from a Man
sh:path (ontology:has-theme ontology:come-from);
sh:class ontology:Man
].
问题是“:a”有两个主题,一个来自人类,另一个来自机器。
然后我在网上读到有关 sh:oneOrMorePath 的内容,并在 sh:property 中尝试了以下变体:
sh:oneOrMorePath (ontology:has-theme ontology:come-from);
sh:path ([sh:oneOrMorePath ontology:has-theme] ontology:come-from);
sh:path (ontology:has-theme [sh:oneOrMorePath ontology:come-from]);
没什么可做的,这些变体也不起作用。
另一方面,如果我删除三元组“:r2 :come-from :m2”或三元组“:a :has-theme :r2” 它有效,因为本体中不再有从“:a”通向非 Man 的分支。
你们中有人可以帮我吗?
谢谢!
利维奥
最佳答案
您的要求规定“在其主题中至少有一个来自男人的结果”,这对我来说听起来像是一种存在主义限制。因此,您不能真正在这里使用 sh:class,但您可能更想使用限定值约束。
我还没有尝试过,但类似这样的方法可能会起作用:
:conditionTest
rdf:type sh:NodeShape ;
sh:property [
sh:path (ontology:has-theme ontology:come-from) ;
sh:qualifiedMinCount 1 ;
sh:qualifiedValueShape [
sh:class ontology:Man ;
]
] .
这应该意味着路径 has-theme/come-from 的至少一个值必须符合限定值形状,这意味着它必须是 Man 的实例。
参见https://www.w3.org/TR/shacl/#QualifiedValueShapeConstraintComponent了解 SHACL 中 QVC 的规范。
如果您可以使用 SHACL-SPARQL 并导入 dash 命名空间,您也可以简单地编写 dash:hasValueWithClass 本体:Man,请参阅 http://datashapes.org/constraints.html#HasValueWithClassConstraintComponent
关于owl - SHACL 规则中的多路径和存在量化(我应该使用 sh :oneOrMorePath perhaps? ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68518850/