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”。前者来自Man“:m1”,后者来自Machine“:m2”。

我想编写一个 SHACL 规则,声明“每个 Approve 操作的主题中至少有一个来自男人的结果是合法的”。

我试过了,它将“: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”有两个主题一个来自 Man,另一个来自 Machine。

然后我在网上阅读了有关 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 的一个实例。

有关 SHACL 中 QVC 的规范,请参阅 https://www.w3.org/TR/shacl/#QualifiedValueShapeConstraintComponent

如果您可以使用 SHACL-SPARQL 并导入 dash 命名空间,您也可以简单地编写 dash:hasValueWithClass ontology:Man,参见 http://datashapes.org/constraints.html#HasValueWithClassConstraintComponent

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...