1

我尝试使用 SHACL 形状验证我的本体实例。但是,我找不到如何说一个给定的属性实例只有当它有一个 Class1 的实例作为主体并且有一个 Class2 的实例作为对象时才有效。

换句话说,我想指定这个属性的域(即Class1)和范围(即Class2)。

在下面的示例中,我们精确地确定范围是(客户和人员),但未指定域。

ex:InvoiceShape
a sh:NodeShape ;
sh:property [
    sh:path ex:customer ;
    sh:class ex:Customer ;
    sh:class ex:Person ;
] .

我知道可以为形状指定目标类 (TC),但这会限制属性 ex:customer 的范围,当域为 TC 时,并非在所有情况下。

是否可以编写一个固定给定属性的域和范围的形状?

谢谢!

4

1 回答 1

2

要声明上述属性约束适用于 ex:Invoice 的所有实例,您可以添加 ex:InvoiceShape rdf:type rdfs:Class 或 ex:InvoiceShape sh:targetClass ex:Invoice。然而,这并没有指定 ex:customer 三元组的所有主题都必须是 ex:Invoice 的实例。

要确保属性 ex:customer只能在 ex:Invoice 的实例中使用,您可以使用:

ex:InverseInvoiceShape
    a sh:NodeShape ;
    sh:targetSubjectsOf ex:customer ;
    sh:class ex:Invoice .

上面的形状适用于 ex:customer 三元组的所有主题。如果该主题不是 ex:Invoice 的实例,则会报告违规行为。

FWIW 您的原始示例指出 ex:customer 的值必须同时是 ex:Customer 和 ex:Person 实例。如果您打算表达“客户或个人”,请使用

ex:InvoiceShape
    a sh:NodeShape ;
    sh:targetClass ex:Invoice ;
    sh:property [
        sh:path ex:customer ;
        sh:or (
            [ sh:class ex:Customer ]
            [ sh:class ex:Person ]
        )
    ] .
于 2019-05-01T04:04:54.267 回答