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环境变量设置为 binTopbraid 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验证器可以构建 来源如下:

  1. 克隆存储库:
git clone https://github.com/TopQuadrant/shacl
  1. 构建包:
cd shacl
mvn clean package 
  1. 部署生成的包。包是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"

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在点击JButton触发的进程仍在处理时更新JLabel?   try-catch为什么Java有嵌套的try语句?   java SSH命令执行失败,出现异常“net.schmizz.sshj.connection.ConnectionException:引发连接重置异常”   java在ApacheCamel的接口类解析器中,resolveMandatoryClass(字符串名称)有什么用途?   java如何在Eclipse远程调试器中找到有问题的线程?   java线程:containerlaunch退出代码127的异常   lambda左连接Java中的2个对象列表   Swift 2.0协议扩展和Java/C抽象类之间有区别吗?   安卓改造:使用GSON将JSON解析为多个Java对象   Spring中服务层的java角色(澄清)   html Java与网站的通信   Spring boot rest api是在不创建java类的情况下将getResultList()转换为映射以显示响应的最佳方法吗?   使用“getElementById”从javascript获取值到java   java如何在文本视图中以粗体和多色显示文本   java是设置TextView颜色的最有效方法