跳转到主要内容

此工具将数据图与从分层配置文件(标准/规范及其配置文件)中提取的SHACL形状图进行验证。

项目描述

CHEKA

一个基于配置文件分层编写的Python RDF图验证工具

  1. 安装
  2. 使用
  3. 测试
  4. 许可证
  5. 引用
  6. 联系方式

此工具将数据图与从分层配置文件(标准/规范及其配置文件)中提取的SHACL形状图进行验证。它使用数据图中对配置文件的符合性声明来收集并使用其他配置文件和标准中的所有验证器SHACL文件。

Cheka使用配置词汇(PROF)描述配置文件和标准,并从配置文件层次结构(遵循prof:isProfileOf属性)以及prof:Profiles到描述为它们实现的约束的prof:ResourceDescriptors进行遍历。这些约束目前仅限于形状约束语言(SHACL)文件,并且必须具有prof:Rolerole:validation才能被Cheka识别。使用pySHACL Python SHACL验证器执行SHACL验证。

安装

  1. 确保您的系统上安装了Python 3
  2. 克隆此存储库
  3. requirements.txt中安装依赖项,例如:~$ pip3 install -r requirements.txt
  4. 按照下面的使用执行脚本

使用

输入需求

要使用Cheka,您必须提供要验证的数据(一个RDF图)和配置文件层次结构(另一个RDF图)。然后它将使用几种选择的策略之一,使用通过配置文件层次结构找到的验证资源来验证数据中的对象。

您还可以提供一些其他标志以执行其他功能。

命令行参数(Python & BASH)如下:

标志 输入值 要求 说明
-d / --data 一个RDF文件的路径 必需 可以是大多数RDF格式,具有常规文件扩展名(例如,.ttl用于Turtle,.jsonld用于JSON-LD)
-p / --profiles 一个配置文件路径 必需 如上所述。配置文件描述必须根据PROF制定
-s / --strategy 'shacl'或'profile' 可选,默认为'shacl' 选择要使用的策略。请参阅下面的策略描述
-u / --profile-uri 配置文件层次结构中配置文件的URI 有时必需 如果选择策略'profile',必须提供配置文件URI。然后,将仅使用该配置文件层次结构中的验证器来验证数据
-r / --get-remotes 可选,默认为False 如果为True,Cheka将拉取配置文件层次结构中引用但未描述的配置文件和验证SHACL工件,即在线远程配置文件

数据图

这必须是一个RDF文件,其中要验证的部分(s)指示它们根据配置文件词汇的配置。

通常看起来像这样

@prefix dct: <http://purl.org/dc/terms/> .

<Object_X>
    a <Class_Y> ;
    dct:conformsTo <Profile_Z> ;
    ...

这意味着<Object_X>旨在符合<Profile_Z>

请参阅tests/文件夹中的示例数据图。

配置文件层次结构

这也必须是一个包含通过prof:isProfileOf属性相互关联的prof:Profile对象层次结构(包括dct:Standard对象)的RDF文件,其中每个对象都有一个通过以下方式与prof:Profile相关联的验证资源,即通过一个prof:ResourceDescriptor,如下所示

@prefix dct: <http://purl.org/dc/terms/> .
@prefix prof: <http://www.w3.org/ns/dx/prof/> .
@prefix role:  <http://www.w3.org/ns/dx/prof/role/> .


<Standard_A>
    a dct:Standard ;
    prof:hasResource [
        a prof:ResourceDescriptor ;
        prof:hasRole role:validation ;
        prof:hasArtifact <File_or_Uri_J> ;
    ]
.

<Profile_B>
    a prof:Profile ;
    prof:isProfileOf <Standard_A> ;
    prof:hasResource <Resource_Descriptor_P> ;
.   

<Resource_Descriptor_P>
    a prof:ResourceDescriptor ;
    prof:hasRole role:validation ;
    prof:hasArtifact <File_or_Uri_K> ;
.

<Profile_C>
    a prof:Profile ; 
    prof:isProfileOf <Profile_B> ;    
    prof:hasResource [
        a prof:ResourceDescriptor ;
        prof:hasRole role:validation ;
        prof:hasArtifact <File_or_Uri_L> ;
    ] ;
.

这意味着<Profile_C><Profile_B>的配置文件,而<Profile_B>又是<Standard_A>的配置文件。这两个配置文件和标准分别具有资源<File_or_Uri_J><File_or_Uri_K><File_or_Uri_L>,由将它们与它们的配置文件/标准相关联的prof:ResourceDescriptor类指示为验证器。

请参阅tests/文件夹中的示例配置文件图。

策略

以下不同的策略可用于选择使用。

名称 描述
shacl 标准SHACL验证:使用配置文件层次结构中找到的所有SHACL验证器,使用SHACL验证器的目标(通常按类)验证给定数据
profile 使用链接到配置文件及其所有配置文件层次结构的验证器验证给定数据。这是Cheka的“主要”策略,与shacl(“正常”SHACL验证)相反
claims 尚未实现,预计2021年2月

shacl 是默认策略

注意策略是通过 -s 标志应用的。当将 Cheka 作为 Python 模块使用时,每个对 Cheka.validate() 的调用都可能应用不同的策略。

运行

Cheka 使用配置文件图来找到它需要验证数据图的所有 SHACL 验证器。它返回一个包含额外元素的 pySHACL 结果 - 验证所使用的配置文件 URI: [conforms, results_graph, results_text, profile_uri]。 conforms 是 True 或 False。

作为 Python 模块

安装 Cheka 后,Python 程序可以导入 Cheka (import cheka)。然后可以在代码中这样调用 Cheka

import cheka

c = cheka.Cheka("data.ttl", "profiles_hierarchy.ttl")

# to tell Cheka to pull in profiles/validators 
# referenced but not defined in the profiles_hierarchy.ttl
c.get_remote_profiles = True  

# a simple validation - basic, default, shacl-only (no use of profiles)
c.validate()

# profile-based vaidation, starting with the profile Profile_C 
c.validate(
    strategy="profile", 
    profile_uri="http://example.org/profile/Profile_C"
)

作为 Python 命令行工具

~$ python3 cli.py -d DATA-GRAPH-FILE -p PROFILES-GRAPH-FILE

(以及可能的其他可选参数)

如果您使 cli.py 脚本可执行(sudo chmod a+x cli.py),则可以像这样运行它

~$ ./cli.py -d DATA-GRAPH-FILE -p PROFILES-GRAPH-FILE

作为 BASH 脚本

位于 bin/ 目录中的文件 cheka 是一个 BASH shell 脚本,它调用 cli.py。将其设置为可执行(sudo chmod a+x cheka),然后可以像这样运行它

~$ ./cheka -d DATA-GRAPH-FILE -p PROFILES-GRAPH-FILE

(以及可能的其他可选参数)

作为 Windows 可执行文件

即将推出!

测试

测试包含在 tests/ 目录中。它们使用 pytest 应该可以从命令行运行。它们没有依赖项,除了 pytest 和 Cheka 本身。

测试注释了它们正在测试的内容。

测试配置文件层次结构

在此代码中的测试中使用的配置文件和验证器组合在文件 test-profile.hierarchy.ttl 中。此层次结构可以用作其他应用程序中配置文件层次结构的示例。

许可证

此代码使用 GPL v3 许可证授权。请参阅 LICENSE 文件 以获取授权书。

有关归属,请参阅下面的 引用

引用

要引用此软件,请使用以下 BibTex

@software{10.5281/zenodo.3676330,
  author = {{Nicholas J. Car}},
  title = {Cheka: A profile hierarchy-based RDF graph validation tool written in Python},
  version = {0.5},
  date = {2020},
  publisher = "SURROUND Australia Pty. Ltd.",
  doi = {10.5281/zenodo.3676330},
  url = {https://doi.org/10.5281/zenodo.3676330}
}

或以下 RDF

@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix sdo: <https://schema.org/> .
@prefix wiki: <https://www.wikidata.org/wiki/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<https://doi.org/10.5281/zenodo.3676330>
    a sdo:SoftwareSourceCode , owl:NamedIndividual ;
    sdo:codeRepository <https://github.com/surroundaustralia/cheka> ;
    dcterms:type wiki:Q7397 ; # "software"
    dcterms:creator "Nicholas J. Car" ;
    dcterms:date "2020"^^xsd:gYear ;
    dcterms:title "Cheka: A profile hierarchy-based RDF graph validation tool written in Python" ;
    sdo:version "0.5" ;
    dcterms:publisher [
        a sdo:Organization ;
        sdo:name "SURROUND Pty Ltd" ;
        sdo:url <https://surroundaustralia.com> ;
    ]
.

联系方式

出版商

SURROUND Australia Pty. Ltd.
https://surroundaustralia.com

创建者
Dr Nicholas J. Car
数据系统架构师
SURROUND Australia Pty. Ltd.
nicholas.car@surroudaustralia.com

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装软件包 的信息。

源分发

cheka-0.7.tar.gz (15.2 kB 查看散列)

上传

构建分发

cheka-0.7-py2.py3-none-any.whl (23.6 kB 查看散列)

上传 Python 2 Python 3

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面