shexSpec / spec

ShEx specification
https://shexspec.github.io/spec/
Other
16 stars 9 forks source link

Require top-level shape declarations #50

Open labra opened 2 years ago

labra commented 2 years ago

One feature that will be useful for ShEx is to have top-level shape definitions which refer to other shapes. For example:

<Human> @<Person>
<Person> { :name . }

This change would imply to add more ceremony to the ShExJ. For example:

{ "type": "Schema",
  "shapes": [
    { "type": "ShapeDecl", "id": "Human",
      "shapeExpr": {
        "type": "Shape",
        "expression": {
          "type": "TripleConstraint",
          "predicate": "http://example.org/name" } } },
    { "type": "ShapeDecl", "id": "Person",
      "shapeExpr": "Human" }
  ]
}

The changes for the ShExJ would look like:

The old ShExJ would represent it like this:

2.1

{
  "type": "Schema",
  "shapes": [
    { "type": "Shape",
      "id": "Human",
      "expression": {
        "type": "TripleConstraint",
        "predicate": "http://example.org/name"
      } }
  ]
}

The new ShExJ would look like:

2.2

{
  "type": "Schema",
  "shapes": [
    { "type": "ShapeDecl",
      "id": "Human",
      "shapeExpr": {
        "type": "Shape",
        "expression": {
          "type": "TripleConstraint",
          "predicate": "http://example.org/name"
        } } }
  ]
}

This is related with this PR: https://github.com/shexSpec/shexTest/pull/49

In order to kepp backwards compatibility we may allow the old ShExJ in version 2.2 marking it as deprecated and adding it as an annex.

ericprud commented 2 years ago

The 2.2 version removes all the labeled* shapeExprs (and therefor has a simpler API):

Schema           {
  "@context":"http://www.w3.org/ns/shex.jsonld"?
  imports:[IRIREF+]?
  startActs:[SemAct+]? start:shapeExprOrRef? shapes:[ShapeDecl|ShapeExternal+]?
 }
ShapeDecl        { id:shapeExprLabel abstract:BOOL? specializes:[IRIREF+]? shapeExpr:shapeExpr }
ShapeExternal    { id:shapeExprLabel }

// Shape Expressions
shapeExpr        = ShapeOr | ShapeAnd | ShapeNot | NodeConstraint | Shape;
shapeExprOrRef   = shapeExpr | shapeExprRef;
ShapeOr          { shapeExprs:[shapeExprOrRef{2,}] }
ShapeAnd         { shapeExprs:[shapeExprOrRef{2,}] }
ShapeNot         { shapeExpr:shapeExprOrRef }
shapeExprRef     = shapeExprLabel ;
shapeExprLabel   = IRIREF | BNODE ;
NodeConstraint   { nodeKind:("iri"|"bnode"|"nonliteral"|"literal")? datatype:IRIREF? xsFacet* values:[valueSetValue+]? }

2.2 example with external:

{ "type": "Schema",
  "shapes": [
    { "type": "ShapeDecl", "id": "S1", "shapeExpr": {
        "type": "Shape", "expression": {
          "type": "TripleConstraint", "predicate": "http://example.org/name"
    } } },
    { "type": "ShapeExternal", "id": "S2" }
  ]
}
ericprud commented 2 years ago

Associated shexTest branch extends_top-level-ShapeDecl passes all JSG tests.