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

Is it possible to write a shape that validates domain and range of a given property?

我尝试使用 SHACL 形状验证我的 ontology 实例。但是,我找不到如何说给定的 属性 实例仅当它具有 Class1 的实例作为主题和 Class2 的实例作为对象时才有效。

也就是说,我要指定这个属性的域(即Class1)和范围(即Class2)。

在下面的例子中,我们精确的范围是(customer and person),但是没有指定域。

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

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

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

谢谢!

要声明上面的 属性 约束适用于 ex:Invoice 的所有实例,您可以添加 ex:InvoiceShape rdf:type rdfs:Class 或 ex:Invoice形状sh:targetClassex: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 实例。如果你想表达 'either customer or 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 ]
        )
    ] .