Skip to content

linkml/ShExJSG

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

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 tests:

uv run pytest

Note for developers

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:

  1. uv sync
  2. uv pip install "pyshexc>=0.10.3"

About

ShEx AST as python classes

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors