Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/edmondchuc/shaclc

A Python SHACL Compact Syntax parser and serializer.
https://github.com/edmondchuc/shaclc

rdf shacl

Last synced: about 2 months ago
JSON representation

A Python SHACL Compact Syntax parser and serializer.

Awesome Lists containing this project

README

        

# Python SHACL Compact Syntax Parser

A Python SHACL Compact Syntax parser and serializer based on the specification at https://w3c.github.io/shacl/shacl-compact-syntax/.

All tests defined in [github.com/w3c/data-shapes/shacl-compact-syntax/tests](https://github.com/w3c/data-shapes/tree/gh-pages/shacl-compact-syntax/tests) are passing.

## Browser playground

Play around with the implementation in your browser at https://edmondchuc.github.io/shaclc/.

## Quickstart

Installation.

```shell
pip install shaclc
```

Usage.

```python
from shaclc import shaclc_to_graph

shaclc_str = """
BASE

IMPORTS

PREFIX ex:

shape ex:PersonShape -> ex:Person {
ex:ssn xsd:string [0..1] pattern="^\\d{3}-\\d{2}-\\d{4}$" .
}
"""

graph = shaclc_to_graph(shaclc_str)

graph.print(format="longturtle")
```

Output.

```
BASE
PREFIX ex:
PREFIX owl:
PREFIX sh:
PREFIX xsd:

<>
a owl:Ontology ;
owl:imports ;
.

<#PersonShape>
a sh:NodeShape ;
sh:property
[
sh:datatype xsd:string ;
sh:maxCount 1 ;
sh:path <#ssn> ;
sh:pattern "^\\d{3}-\\d{2}-\\d{4}$" ;
] ;
sh:targetClass <#Person> ;
.
```