【问题标题】:SHACL sh:rule with sh:condition in SPARQL in Topbraid ComposerTopbraid Composer 中 SPARQL 中的 SHACL sh:rule 和 sh:condition
【发布时间】:2022-01-20 08:58:15
【问题描述】:

示例本体有两个类(:MyClass:Value)和两个属性(:MyObjProp:MyDataProp)。

:MyClass
  a owl:Class ;
  a sh:NodeShape ;
  rdfs:subClassOf owl:Thing ;
.
:MyDataProp
  a owl:DatatypeProperty ;
  rdfs:domain :MyClass ;
  rdfs:range xsd:string ;
.
:MyObjProp
  a owl:ObjectProperty ;
  rdfs:domain :MyClass ;
  rdfs:range :Value ;
.
:Value
  a owl:Class ;
  rdfs:subClassOf owl:Thing ;
.

添加了一些实例。

:MyClass_1
  a :MyClass ;
  :MyDataProp :Value_1 ;
  :MyObjProp :Value_1 ;
.
:MyClass_2
  a :MyClass ;
  :MyObjProp :Value_2 ;
.
:Value_1
  a :Value ;
.
:Value_2
  a :Value ;
.

创建了带有 sh:rule (:SPARQLRule_1) 的 NodeShape :NodeShapeRule。此规则创建新的三元组。使用sh:condition 时,该规则应仅限于目标子集。

:NodeShapeRule
  a sh:NodeShape ;
  sh:rule :SPARQLRule_1 ;
  sh:targetClass :MyClass ;
.
:SPARQLRule_1
  a sh:SPARQLRule ;
  sh:condition :NodeShapeConditionSPARQL ;
  sh:construct """
    PREFIX : <http://example.org/ex#>
    CONSTRUCT
    {
        $this :MyDataProp \"New input\" .
    }
    WHERE
    {
        $this :MyObjProp ?p .
    }
    """ ;
.

为限制定义了两个等效的 NodeShape。第一个约束使用 sh:property,另一个使用 sh:sparql。

:NodeShapeConditionProperty
  a sh:NodeShape ;
  sh:property [
      sh:path :MyObjProp ;
      sh:description "NodeShapeConditionProperty" ;
      sh:hasValue :Value_1 ;
    ] ;
  sh:targetClass :MyClass ;
.
:NodeShapeConditionSPARQL
  a sh:NodeShape ;
  sh:sparql [
      sh:message "NodeShapeConditionSPARQL" ;
      sh:prefixes <http://example.org/ex> ;
      sh:select """
        PREFIX : <http://example.org/ex#>
        SELECT $this
        WHERE
        {
            $this :MyObjProp ?prop .
        }
        """ ;
    ] ;
  sh:targetClass :MyClass ;
.

在使用 Topbraid Composer 进行推理时,我收到了两种解决方案的不同结果。只有带有 sh:property 的解决方案才能提供预期的响应。请问,有人可以解释一下这种行为吗?

:MyClass_1 :MyDataProp "New input"

【问题讨论】:

  • example.org/ex 是否正确声明了默认前缀? (此类问题最好在允许附加完整文件的平台上处理。因此 topbraid-users 邮件列表是一种替代方法)。
  • 是的,默认前缀声明正确。
  • 既然我们已经在其他地方解决了这个问题,您会在此处关闭或删除此项目吗?

标签: sparql rules inference shacl


【解决方案1】:

正确的解释是 SPAQRL 查询为 SELECT 查询中的每个结果(行)产生一个约束冲突。因此,如果 SPARQL 查询没有返回结果(行),那么一切都很好,规则将触发。这种设计的原因是这使 SPARQL 查询能够返回有关违规的更多信息,例如焦点节点($this)和值节点(?value)。

更改 :NodeShapeConditionSPARQL 会导致不存在的结果违规,然后两种解决方案的行为方式相同。

:NodeShapeConditionSPARQL
  a sh:NodeShape ;
  sh:sparql [
      sh:message "NodeShapeConditionSPARQL" ;
      sh:prefixes <http://example.org/ex> ;
      sh:select """
        PREFIX : <http://example.org/ex#>
        SELECT $this
        WHERE
        {
            FILTER NOT EXISTS { $this :MyObjProp ?anyProp } .
        }
        """ ;
    ] ;
  sh:targetClass :MyClass ;
.

【讨论】:

    猜你喜欢
    • 2014-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-19
    • 1970-01-01
    相关资源
    最近更新 更多