This repository was originally developed by Harold Solbrig and was kindly contributed to the LinkML organization because of his retirement. All credit for the original development of this repository goes to him.
Python representation of the ShEx AST(ish) specification.
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= { }
This file is derived from the ShEx JSG specification. The differences are as follows:
labeledShapeExpr- The official JSG implemention specifies a strange pattern where the objects with atypeof"ShapeOr","ShapeAnd", ... are recognized as instances ofShapeOr,ShapeAnd, ... if they lack anidelement and aslabeledShapeOr,labeledShapeAnd, ... if theidelement exists. We simplify this construct, leavingidoptional. 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 thelabeledShapeExprbranch)- This uses the revised jsg syntax.
Output of the PyJSG generate_parser for ShExJ.jsg. Python 3 representation of the ShEx AST
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
cd ShExJSG
generate_parser ShExJ.jsgThen run all tests:
uv run pytest
The original way this library was developed created a circular dependency for the test environment, causing uv to fail
to resolve. The reason is that ShExJSG is a runtime dependency for pyshexc, while pyshexc is a dev dependency for
ShExJSG. The only way around this is to run the development install the following way after cloning:
uv syncuv pip install "pyshexc>=0.10.3"