将所有节点用于验证

问题描述 投票:0回答:1

使用https://shacl.org/playground/,我有以下形状图:

@prefix hr: <http://learningsparql.com/ns/humanResources#> .
@prefix d:  <http://learningsparql.com/ns/data#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

hr:ClassShape
    a sh:NodeShape ;
    sh:targetNode hr:Employee;

    sh:property [                
        sh:path rdf:type ;
        sh:nodeKind sh:IRI ;
        sh:hasValue rdfs:Class
    ] ; 
    sh:closed true ;
.

和以下数据图:

@prefix hr: <http://learningsparql.com/ns/humanResources#> .
@prefix d:  <http://learningsparql.com/ns/data#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

#### Regular RDFS modeling ####

hr:Employee a rdfs:Class .

hr:name
   rdf:type rdf:Property ; .

我想验证数据图中的每个节点的rdf:type为rdfs:Class还是rdf:Property。

可以使用SHACL吗?如果是这样,如何?

我遇到的问题是,我认为我需要指定一个sh:targetNode并具体说明我要定位的节点。我还没有看到使用“ *”之类的通配符来指定数据图中每个节点的方法。

validation rdf turtle-rdf shacl
1个回答
0
投票

以下形状图至少提供了部分解决方案。

@prefix hr: <http://learningsparql.com/ns/humanResources#> .
@prefix d:  <http://learningsparql.com/ns/data#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

hr:ClassShape
    a sh:NodeShape ;
    sh:targetSubjectsOf rdf:type;

    sh:or (
        [                
            sh:path rdf:type ;
            sh:nodeKind sh:IRI ;
            sh:hasValue rdfs:Class;
        ]
        [                
            sh:path rdf:type ;
            sh:nodeKind sh:IRI ;
            sh:hasValue rdf:Property;
        ]
    );

    sh:closed true ;
.

仍有尚待解决的验证错误(不允许谓词(闭合形状)),但是允许检查所有节点的键是sh:targetSubjectsOf rdf:type;,其中指出每个具有rdf:type的节点,该对象必须是Class或Property。

缺少的是验证每个节点都有一个rdf:type

© www.soinside.com 2019 - 2024. All rights reserved.