weso / shapes-rs

RDF data shapes implementation in Rust
https://www.weso.es/shapes-rs/
Apache License 2.0
23 stars 1 forks source link

Nesting of ANDs seems to be different to the one specified in the shex_testsuite #13

Open labra opened 7 months ago

labra commented 7 months ago

The following example behaves different than in the shex.js.

base <x:/>
<S1> {
 <p> BNODE {} AND IRI
}
<S2> BNODE {} AND IRI

In shex-rs parser, the results of the shape expression BNODE {} AND IRI are not flattened, i.e. the results are:

{
  "@context": "http://www.w3.org/ns/shex.jsonld",
  "type": "Schema",
  "shapes": [
    {
      "type": "ShapeDecl",
      "id": "x:S1",
      "abstract": false,
      "shapeExpr": {
        "type": "Shape",
        "expression": {
          "type": "TripleConstraint",
          "predicate": "x:p",
          "valueExpr": {
            "type": "ShapeAnd",
            "shapeExprs": [
              {
                "type": "ShapeAnd",
                "shapeExprs": [
                  {
                    "type": "NodeConstraint",
                    "nodeKind": "bnode"
                  },
                  {
                    "type": "Shape"
                  }
                ]
              },
              {
                "type": "NodeConstraint",
                "nodeKind": "iri"
              }
            ]
          }
        }
      }
    },
    {
      "type": "ShapeDecl",
      "id": "x:S2",
      "abstract": false,
      "shapeExpr": {
        "type": "ShapeAnd",
        "shapeExprs": [
          {
            "type": "ShapeAnd",
            "shapeExprs": [
              {
                "type": "NodeConstraint",
                "nodeKind": "bnode"
              },
              {
                "type": "Shape"
              }
            ]
          },
          {
            "type": "NodeConstraint",
            "nodeKind": "iri"
          }
        ]
      }
    }
  ],
  "base": "x:/"

But in shex.js, (try it) the results of the first appearance are flattened:

{
  "type": "Schema",
  "shapes": [
    {
      "type": "ShapeDecl",
      "id": "x:/S1",
      "shapeExpr": {
        "type": "Shape",
        "expression": {
          "type": "TripleConstraint",
          "predicate": "x:/p",
          "valueExpr": {
            "type": "ShapeAnd",
            "shapeExprs": [
              {
                "type": "NodeConstraint",
                "nodeKind": "bnode"
              },
              {
                "type": "Shape"
              },
              {
                "type": "NodeConstraint",
                "nodeKind": "iri"
              }
            ]
          }
        }
      }
    },
    {
      "type": "ShapeDecl",
      "id": "x:/S2",
      "shapeExpr": {
        "type": "ShapeAnd",
        "shapeExprs": [
          {
            "type": "ShapeAnd",
            "shapeExprs": [
              {
                "type": "NodeConstraint",
                "nodeKind": "bnode"
              },
              {
                "type": "Shape"
              }
            ]
          },
          {
            "type": "NodeConstraint",
            "nodeKind": "iri"
          }
        ]
      }
    }
  ],
  "@context": "http://www.w3.org/ns/shex.jsonld"
}
labra commented 5 months ago

I notified Eric Prud'hommeaux and it seems to be a bug in the official test-suite.