UNPKG

shaclc-parse

Version:

A parser for files written with SHACL compact syntax

79 lines (58 loc) 2.42 kB
# shaclc-parse A parser for files written with [SHACL compact syntax](https://w3c.github.io/shacl/shacl-compact-syntax/) ## Usage ```ts import { parse } from 'shaclc-parse' const quads = parse(` PREFIX ex: <http://example.org/test#> shape ex:TestShape -> ex:TestClass1 ex:TestClass2 { targetNode=ex:TestNode targetSubjectsOf=ex:subjectProperty targetObjectsOf=ex:objectProperty . } `, { baseIRI: "http://example.org/basic-shape-with-targets" }) ``` ## Extended SHACL Compact Syntax The [SHACL Compact Syntax specification](https://w3c.github.io/shacl/shacl-compact-syntax/) is not expressive enough to make any RDF 1.0 statement. This package includes an opt-in extended syntax that allows users to make any RDF 1.0 statement. Parsing of this extended syntax can be enabled via an option in the `parse` function ```ts const quads = parse(/*shaclc extended string*/, { extendedSyntax: true }) ``` ### Making additional statements about the `NodeShape` Additional statements can be made about NodeShapes by using a turtle-like syntax before the body of the shape. For instance we can add the following statements to the above `ex:TestShape`. ```ttl ex:TestShape ex:myCustomAnnotation ex:myCustomValue ; ex:myCustomBlankNodeAnnotation [ ex:myCustomList ( 1 ex:myCustomValue ) ] . ``` by doing the following: ```shaclc shape ex:TestShape -> ex:TestClass1 ex:TestClass2 ; ex:myCustomAnnotation ex:myCustomValue ; ex:myCustomBlankNodeAnnotation [ ex:myCustomList ( 1 ex:myCustomValue ) ] { targetNode=ex:TestNode targetSubjectsOf=ex:subjectProperty targetObjectsOf=ex:objectProperty . } ``` ### Making additional statements about the `sh:property` additional statements can be made about each blank node property as follows: ```shaclc shape ex:TestShape -> ex:TestClass1 ex:TestClass2 { ex:myPath [0..1] % ex:myCustomPropertyAnnotation ex:myCustomPropertyValue ; ex:myCustomPropertyAnnotation2 ex:myCustomPropertyValue2 ; % . } ``` ### Making arbitrary statements Finally we permit the use of turtle syntax at the end of the file to make any additional statements ```shaclc shape ex:TestShape -> ex:TestClass1 ex:TestClass2 { targetNode=ex:TestNode targetSubjectsOf=ex:subjectProperty targetObjectsOf=ex:objectProperty . } ex:bob a ex:Person . ``` ## License ©2022–present [Jesse Wright](https://github.com/jeswr), [MIT License](https://github.com/jeswr/shaclcjs/blob/main/LICENSE).