1

我想使用 SHACL 检查建筑项目的传入数据集。为此,我在类级别定义了几个约束。在我的用例中,我需要能够对指定实例的这些约束进行项目特定异常。这在 SHACL 中可能吗?这个怎么建模?

最后,我想在不同的形状图(SG)中描述这些约束:

  • 通用SG,无一例外地遵守规则;
  • 项目 SG,在一般 SG 中包含特定项目相关的约束和约束例外。

我可以想到诸如 SHACL-SPARQL 之类的变通方法,或者首先检查一般 SG,然后使用过滤器忽略项目特定的异常,但我想知道是否有针对这种情况的更干净的解决方案。

下面是一个简化的例子来说明这个问题:


数据图可能如下所示:

@prefix schema: <http://www.example.org/schema#> .
@prefix : <http://www.example.org/data#> .

schema:Building  a  owl:Class .

:CorrectBuilding a schema:Building ;
  schema:owner "John Doe" ;
  schema:otherProp "Some other prop" .

:IncorrectBuilding a schema:Building ;
  schema:otherProp "Some other prop" .

:BuildingWithException a schema:Building ;
  schema:otherProp "Some other prop" .

一般的 SG 可能如下所示:

@prefix schema: <http://www.example.org/schema#> .
@prefix : <http://www.example.org/data#> .
@prefix gsg: <http://www.example.org/generalsg#>

gsg:PersonShape
    a sh:NodeShape ;
    sh:targetClass schema:Building ;
    sh:property [              
        sh:path schema:owner ;       
        sh:minCount 1 ;
    ] .

使用上述和项目特定的 SG,验证器应该返回 的违规:IncorrectBuilding,而不是:BuildingWithException

我怎样才能为项目制作特定的例外:BuildingWithException

感谢您的阅读,让我知道您的想法。

4

1 回答 1

0

我认为这是使用SHACL-AF Custom Targets的情况,如果您可以在您的环境中使用它们:

@prefix schema: <http://www.example.org/schema#> .
@prefix : <http://www.example.org/data#> .
@prefix gsg: <http://www.example.org/generalsg#>
@prefix sh:    <http://www.w3.org/ns/shacl#> .

gsg: 
    sh:declare [
        sh:prefix "schema" ;
        sh:namespace "http://www.example.org/schema#" ; 
    ] ;
    sh:declare [
        sh:prefix "data" ;
        sh:namespace "http://www.example.org/data#" ; 
    ] .

gsg:PersonShapeWithException
    a sh:NodeShape ;
    sh:target [
        a sh:SPARQLTarget ;
        sh:prefixes gsg: ;
        sh:select """
        SELECT ?node 
        WHERE {
            ?node a schema:Building 
            FILTER (?node != data:IncorrectBuilding)
        }
        """ ;
    ] ;
    sh:property [              
        sh:path schema:owner ;       
        sh:minCount 1 ;
    ] .

产生:

[ a            sh:ValidationReport ;
  sh:conforms  false ;
  sh:result    [ a                             sh:ValidationResult ;
                 sh:focusNode                  :BuildingWithException ;
                 sh:resultMessage              "Property needs to have at least 1 values, but found 0" ;
                 sh:resultPath                 schema:owner ;
                 sh:resultSeverity             sh:Violation ;
                 sh:sourceConstraintComponent  sh:MinCountConstraintComponent ;
                 sh:sourceShape                []
               ]
] .

于 2020-05-27T10:44:15.927 回答