簡體   English   中英

定位某個 class 的所有對象,SHACL 中指定的實例除外

[英]Target all of a certain class, except for a specified instance in SHACL

我想使用 SHACL 檢查建築項目的傳入數據集。 為此,我在 class 級別定義了幾個約束。 在我的用例中,我需要能夠對指定實例的這些約束進行項目特定異常。 這在 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創建項目特定的異常?

感謝您的閱讀,讓我知道您的想法。

我認為這是使用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                []
               ]
] .

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM