Topbraid shacl验证器的python包装器
pyTBSHACL的Python项目详细描述
Pytbshacl
topquadrant的topbraid shacl验证器的python包装器。
PySHACL用于rdflib
does not currently implement
一些advanced SHACL functionality
可与TopBraid's command line validator一起使用。
pyTBSHACL
为topbaid验证器工具实现一个python包装器
帮助简化与python项目的集成
需要这个功能。预计本单元将
随着高级能力逐渐添加到pyshacl中,变得多余。
状态
版本0.0.1(2019-08-21):
初步完全实施。形状文件必须在Turtle中,数据文件 可以是rdflib支持的任何rdf格式。以Turtle格式输出,纯文本, 或者json。仅在OS X上测试。
安装
一。下载并安装Topbraid Shacl验证器,请遵循以下指南:
https://github.com/TopQuadrant/shacl
(可选)从源代码构建验证器,请参阅“构建验证器” 从下面的“来源”。
2.将SHACLROOT
环境变量设置为
bin
Topbraid Shacl验证程序分发的文件夹。
三。pip install -U pyTBSHACL
或将此repo、cd克隆到文件夹,
然后运行:pip install -e .
示例
下面是从examples
文件夹运行的。
有效数据:
$ shacl -d data_00a.ttl -s shape_00.ttl
@prefix ex: <http://example.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
[ a sh:ValidationReport ;
sh:conforms true
] .
无效数据:
$ shacl -d data_00b.ttl -s shape_00.ttl
@prefix ex: <http://example.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
[ a sh:ValidationReport ;
sh:conforms false ;
sh:result [ a sh:ValidationResult ;
sh:focusNode ex:bob ;
sh:resultMessage "Does not have value ex:Mathematics" ;
sh:resultPath ex:field ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:HasValueConstraintComponent ;
sh:sourceShape []
]
] .
文本输出的数据无效:
$ shacl -d data_00b.ttl -s shape_00.ttl -of text
Validation Report
Conforms: False
Results (1):
Results for focus node http://example.org/bob:
Path: http://example.org/field
Severity: Violation
Constraint violation in HasValueConstraintComponent
Message: Does not have value ex:Mathematics
Source shape: ub2bL15C48
编码为json ld:
的有效数据集$ shacl -d data_01a.json -df json-ld -s shape_01.ttl
@prefix : <http://schema.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
[ a sh:ValidationReport ;
sh:conforms true
] .
无效的数据集编码:
$ shacl -d data_01b.ttl -s shape_01.ttl
@prefix schema: <http://schema.org/> .
@prefix ex: <http://example.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
[ a sh:ValidationReport ;
sh:conforms false ;
sh:result [ a sh:ValidationResult ;
sh:focusNode ex:dataset2_encoding ;
sh:resultMessage "A schema:contentUrl is required for the encoding property of a Dataset" ;
sh:resultPath schema:contentUrl ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:MinCountConstraintComponent ;
sh:sourceShape <http://ns.dataone.org/schema/2019/08/SO/Dataset#contentUrlConstraint0>
] ;
sh:result [ a sh:ValidationResult ;
sh:focusNode ex:dataset2_encoding ;
sh:resultMessage "Property needs to have at least 1 values, but found 0" ;
sh:resultPath schema:encodingFormat ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:MinCountConstraintComponent ;
sh:sourceShape <http://ns.dataone.org/schema/2019/08/SO/Dataset#encodingFormatConstraint0>
] ;
sh:result [ a sh:ValidationResult ;
sh:focusNode [] ;
sh:resultMessage "Property needs to have at least 1 values, but found 0" ;
sh:resultPath schema:encodingFormat ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:MinCountConstraintComponent ;
sh:sourceShape <http://ns.dataone.org/schema/2019/08/SO/Dataset#encodingFormatConstraint0>
]
] .
从源代码构建验证程序
最新版本的topbraid shacl验证器可以构建 来源如下:
- 克隆存储库:
git clone https://github.com/TopQuadrant/shacl
- 构建包:
cd shacl
mvn clean package
- 部署生成的包。包是
target
中的.zip文件。 名为“的文件夹。将该文件解压缩到所需的安装 位置,例如:
cd ~/bin
unzip ~/git/shacl/target/shacl-1.x.y-SNAPSHOT-bin.zip
export SHACLROOT="~/git/shacl/target/shacl-1.x.y-SNAPSHOT/bin"