shex.js

NPM Version ShapeExpressions Gitter chat https://gitter.im/shapeExpressions/Lobby DOI

@shexjs/visitor

Visitor pattern for traversing ShExJ schemas

install

npm install --save @shexjs/visitor

Quick Start

The default behavior is to return a copy of the passed schema:

node -e 'console.log(JSON.stringify(new (require("@shexjs/visitor"))()
  .visitSchema(
    {
      "type": "Schema",
      "shapes": [
        {
          "id": "http://a.example/S1",
          "type": "Shape",
          "expression": {
            "type": "TripleConstraint",
            "predicate": "http://a.example/p1",
            "valueExpr": {
              "type": "NodeConstraint",
              "values": [
                {
                  "value": "1",
                  "type": "http://www.w3.org/2001/XMLSchema#integer"
                },
                {
                  "value": "2",
                  "type": "http://www.w3.org/2001/XMLSchema#integer"
                }
              ]
            }
          }
        }
      ]
    }), null, 2))'

The result is will look identical to the input schema

Strategy

The ShExJ format is defined in JSG or Typescript. The visitor API reflects both the names of the ShExJ attributes and their types. For example, by default, the visitShapeAnd calls visitShapeExpr on each of the conjuncts. Likewise, visitTripleConstraint calls visitValueExpr on the .valueExpr attribute, which in turn calles visitShapeExpr because that is the type of .valueExpr.

Methods

simple value visitors

index(schema)

The index function creates a visitor and overrides visitExpression and visitShapeExpr to provide an index composed of two maps:

Lerna Monorepo

This repo uses lerna to manage multiple NPM packages. These packages are located in packages/*: