Home

Awesome

ShExJSG -

Python representation of the ShEx AST(ish) specification.

Pyversions PyPi Build Publish

Use:

from ShExJSG import Schema, ShExJ
from PyShExC import ShExC
from pyjsg.jsglib.loader import is_valid

schema = Schema()

schema.start = ShExJ.Shape()

print(is_valid(schema))
print(schema._as_json_dumps())
print(str(ShExC(schema)))
True
{
   "@context": "http://www.w3.org/ns/shex.jsonld",
   "start": {
      "type": "Shape"
   },
   "type": "Schema"
}
 start=  { }

ShExJ.jsg

This file is derived from the ShEx JSG specification. The differences are as follows:

  1. labeledShapeExpr - The official JSG implemention specifies a strange pattern where the objects with a type of "ShapeOr", "ShapeAnd", ... are recognized as instances of ShapeOr, ShapeAnd, ... if they lack an id element and as labeledShapeOr, labeledShapeAnd, ... if the id element exists. We simplify this construct, leaving id optional. This potentially allows the parser to accept some highly unlikely invalid constructs, but these can be checked in a post-parse step if you feel deeply about it. (Note also that the ShEx semantics document does not include the labeledShapeExpr branch)
  2. This uses the revised jsg syntax.

ShExJ.py

Output of the PyJSG generate_parser for ShExJ.jsg. Python 3 representation of the ShEx AST

Installation

This package currently requires python 3.6 or later. It could be updated to support earlier python 3 versions if there is sufficient demand.

pip install ShExJSG

Updating the parser

cd ShExJSG
generate_parser ShExJ.jsg

Then run all of the unit tests