owl - SHACL 规则中的多路径和存在量化(我应该使用 sh:oneOrMorePath 吗?)
问题描述
我想了解如何在 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”。前者来自人“:m1”,后者来自机器“: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" 对非人。
你们中的任何人都可以帮助我吗?
谢谢!
利维奥
解决方案
您的要求声明“在其主题中至少有一个来自男人的结果”,这对我来说听起来像是一种存在约束。所以你不能在这里真正使用 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 的实例。
有关SHACL 中 QVC 的规范,请参阅https://www.w3.org/TR/shacl/#QualifiedValueShapeConstraintComponent 。
如果您可以使用 SHACL-SPARQL 并导入 dash 命名空间,您也可以简单地编写 dash:hasValueWithClass 本体:Man,参见http://datashapes.org/constraints.html#HasValueWithClassConstraintComponent
推荐阅读
- java - 同步方法中的重入
- reactjs - 如何将数据值从一个子组件传递到 React 中的另一个子组件?
- pandas - 如何在pyspark的熊猫UDF中写入csv?
- spring - Spring Boot Actuator 端点未在没有控制器的应用程序中公开
- graphql - Apollo Federation:在扩展类型的同时本地开发底层服务
- python - Django 部署教程中的 Google App Engine 资源错误
- javascript - 调用返回 Observable 而不是实际对象
- javascript - React Component 没有从 reducer 获取更新的状态
- django - 如何让 PIL 的 Image.open 从静态中查找文件?
- javascript - 替换字符串对象属性全局