首页 > 解决方案 > SHACL 验证列表并检索受约束的属性路径

问题描述

我正在根据 TopQuadrant 的这个示例进行一些测试,并使用Zazuko SHACL Playground

我正在尝试针对期望属性为列表的形状验证数据,我的目标是检索无效属性的路径。

这是我使用的数据:

@prefix dash: <http://datashapes.org/dash#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix ex: <http://www.example.com/rdf#> .

ex:MyTrafficLight
    a ex:TrafficLight ;
    ex:label 'myTrafficLight';
    ex:id 'TL12345';
    ex:colors [
        rdf:first "red" ;
        rdf:rest [
            rdf:first "yellow" ;
            rdf:rest [
                rdf:first "green" ;
                rdf:rest rdf:nil ;
            ]
        ]
    ] .

以及它被测试的形状:

@prefix dash: <http://datashapes.org/dash#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix ex: <http://www.example.com/rdf#> .

ex:TrafficLightShape
    a sh:NodeShape ;
    sh:targetClass ex:TrafficLight ;
    sh:property [
        sh:path ex:label;
        sh:datatype xsd:string;
    ];
    sh:property [
        sh:path ex:id;
        sh:datatype xsd:string;
    ];
    sh:property [
        sh:path ex:colors ;
        sh:node dash:ListShape ;
        sh:property [
            sh:path ( [ sh:zeroOrMorePath rdf:rest ] rdf:first ) ;
            sh:datatype xsd:string ;
        ]
    ] .

这工作正常,但是如果我将ex:colors成员的预期数据类型更改为xsd:float,这是生成的验证报告:

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

_:genid1
  a <http://www.w3.org/ns/shacl#ValidationResult> ;
  ns0:resultSeverity ns0:Violation ;
  ns0:sourceConstraintComponent ns0:DatatypeConstraintComponent ;
  ns0:sourceShape _:genid2 ;
  ns0:focusNode _:genid3 ;
  ns0:value "yellow" ;
  ns0:resultPath (
   _:genid5
   rdf:first
 ) ;
  ns0:resultMessage "Value does not have datatype <http://www.w3.org/2001/XMLSchema#float>" .

_:genid2
  ns0:path (
   _:genid5
   rdf:first
 ) ;
  ns0:datatype xsd:float .

_:genid5 ns0:zeroOrMorePath rdf:rest .
_:genid3
  ns0:path <http://www.example.com/rdf#label> ;
  ns0:datatype xsd:string .

_:genid7
  a ns0:ValidationResult ;
  ns0:resultSeverity ns0:Violation ;
  ns0:sourceConstraintComponent ns0:DatatypeConstraintComponent ;
  ns0:sourceShape _:genid2 ;
  ns0:focusNode _:genid3 ;
  ns0:value "green" ;
  ns0:resultPath (
   _:genid5
   rdf:first
 ) ;
  ns0:resultMessage "Value does not have datatype <http://www.w3.org/2001/XMLSchema#float>" .

_:genid8
  a ns0:ValidationResult ;
  ns0:resultSeverity ns0:Violation ;
  ns0:sourceConstraintComponent ns0:DatatypeConstraintComponent ;
  ns0:sourceShape _:genid2 ;
  ns0:focusNode _:genid3 ;
  ns0:value "red" ;
  ns0:resultPath (
   _:genid5
   rdf:first
 ) ;
  ns0:resultMessage "Value does not have datatype <http://www.w3.org/2001/XMLSchema#float>" .

[]
  a ns0:ValidationReport ;
  ns0:conforms false ;
  ns0:result _:genid1, _:genid7, _:genid8 .

我的问题是没有关于我的形状()上失败的属性的路径是什么的信息,只有用于描述列表sh:path ex:colors的“子属性”( )的路径。sh:path ( [ sh:zeroOrMorePath rdf:rest ] rdf:first )

有没有办法检索这些信息?形状是否应该以不同的方式定义?

标签: rdfshacl

解决方案


推荐阅读