o-development / ldo-legacy

Linked Data Objects
Other
19 stars 2 forks source link

Support for recursive shapes #10

Closed megoth-capgemini closed 1 year ago

megoth-capgemini commented 1 year ago

While trying out LDO and ShEx shapes, I noticed that recursive shapes don't seem to be supported. E.g. the following shape will result in an TypeError:

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX ldp: <http://www.w3.org/ns/ldp#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

<Resource> EXTRA rdf:type {
  rdf:type [ ldp:BasicContainer ldp:Resource ldp:Container ] ;
  ldp:contains <Resource>* ;
}

The TypeError looks like the following:

node_modules\ldo-cli\dist\build.js:109
                                                                context: JSON.stringify(context, null, 2),
                                                                              ^

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property 'shapeExpr' -> object with constructor 'Object'
    |     property 'expression' -> object with constructor 'Object'
    |     ...
    |     property 'valueExpr' -> object with constructor 'Object'
    --- property 'datatype' closes the circle

Have I misunderstood something, or is there no support for recursive shapes yet? (For more on recursive shapes, check http://shex.io/shex-semantics/index.html#example-recursion.) Is there plans to support recursive shapes?

jaxoncreed commented 1 year ago

There should be support for recursive shapes. This might be a bug. I'll look into it.

megoth commented 1 year ago

Apologies, my initial example was flawed. I've experimented a bit more, and the following seems to work:

solid:ContainerShape EXTRA rdf:type {
  rdf:type [ ldp:BasicContainer ldp:Container ] ;
  ( ldp:contains @solid:ContainerShape | ldp:contains @solid:ResourceShape )* ;
}

solid:ResourceShape EXTRA rdf:type {
  rdf:type [ldp:Resource] ;
}

I'll close this issue, but feel free to reopen if I've misunderstood something.