o-development / ldo-legacy

Linked Data Objects
Other
19 stars 2 forks source link

Building shape with OR keyword fails (Unknown kind undefined) #12

Open mrkvon opened 1 year ago

mrkvon commented 1 year ago

edit: this issue is rather related to ldo-cli, and repository owners could move it there, sorry for the mess

When i run yarn run build:ldo with shex that contains OR keyword, i get the following error:

(node:570777) UnhandledPromiseRejectionWarning: Error: Unknown kind undefined
    at writeReference (/path/to/your/project/node_modules/dts-dom/bin/index.js:632:27)
    at printMember (/path/to/your/project/node_modules/dts-dom/bin/index.js:561:21)
    at printObjectTypeMembers (/path/to/your/project/node_modules/dts-dom/bin/index.js:502:13)
    at writeInterface (/path/to/your/project/node_modules/dts-dom/bin/index.js:694:9)
    at writeDeclaration (/path/to/your/project/node_modules/dts-dom/bin/index.js:959:28)
    at Object.emit (/path/to/your/project/node_modules/dts-dom/bin/index.js:380:5)
    at /path/to/your/project/node_modules/shexj2typeandcontext/dist/typing/shexjToTyping.js:95:34
    at Array.map (<anonymous>)
    at /path/to/your/project/node_modules/shexj2typeandcontext/dist/typing/shexjToTyping.js:92:44
    at step (/path/to/your/project/node_modules/shexj2typeandcontext/dist/typing/shexjToTyping.js:63:23)

For example, the following shape (WAC Authorization) fails:

PREFIX wac: <http://www.w3.org/ns/auth/acl#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX ex: <https://example.com/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

ex:Authorization EXTRA a {
  a wac:Authorization ;
  wac:accessTo IRI+ ;
  wac:default IRI? ;
  wac:agent @ex:AgentClass OR @ex:Agent;
  wac:mode (wac:Read OR wac:Write OR wac:Append OR wac:Control)+ ;
  wac:origin (@ex:Origin OR wac:AnyOrigin)? ;
  wac:referrer (@ex:Referrer OR wac:AnyReferrer)? ;
  wac:accessToClass IRI? ;
  wac:defaultForNew IRI? ;
  wac:delegate IRI? ;
  wac:inherited IRI? ;
  wac:app IRI? ;
  wac:trustedApp IRI? ;
  wac:applyToPublic xsd:boolean? ;
  wac:applyTo IRI? ;
  wac:defaultForNew xsd:boolean? ;
}

ex:AgentClass EXTRA a {
  a wac:AgentClass ;
  wac:agentClass IRI+ ;
}

ex:Agent EXTRA a {
  a wac:Agent ;
  foaf:name xsd:string? ;
  wac:agentClass IRI? ;
  wac:agentGroup IRI? ;
  wac:agentAny IRI? ;
  wac:agentAll IRI? ;
  wac:agentNone IRI? ;
}

ex:Origin {
  a wac:Origin ;
  wac:originUrl xsd:anyURI+;
}

ex:Referrer {
  a wac:Referrer ; wac:referrerUrl xsd:anyURI+
}

I'd expect the build to pass and produce union type (e.g. Agent | AgentClass)

Initial debugging

It seems that dts-dom doesn't receive a correct configuration to produce the typings. Somewhere along the way,

 {
  shapeExprs: [
    {
      name: 'AgentClass',
      baseTypes: [],
      typeParameters: [],
      kind: 'interface',
      members: [Array],
      flags: 0,
      shapeId: 'https://example.com/AgentClass'
    },
    {
      name: 'Agent',
      baseTypes: [],
      typeParameters: [],
      kind: 'interface',
      members: [Array],
      flags: 0,
      shapeId: 'https://example.com/Agent'
    }
  ]
}

doesn't get transformed into { kind: 'union', members: [...], ... }

jaxoncreed commented 1 year ago

Thanks for pointing this out.

megoth-capgemini commented 1 year ago

Just want to chime in that I'm having the same problem (I think so, at least), with the given ShEx input:

shape:Chapter EXTRA rdf:type {
  rdf:type [ selaw:Chapter ] ;
  dct:title xsd:string ;
  selaw:referenceNumber xsd:string ;
  ( dct:hasPart @shape:Section* | dct:hasPart @shape:Paragraph* ) ;
}

shape:Section EXTRA rdf:type {
  rdf:type [ selaw:Section ] ;
  dct:title xsd:string ;
  dct:hasPart @shape:Paragraph* ;
}

shape:Paragraph EXTRA rdf:type {
  rdf:type [ selaw:Paragraph ] ;
  rdf:value xsd:string ;
  selaw:referenceNumber xsd:string ;
  dct:hasPart @shape:ListItem* ;
}

The interesting part here is ( dct:hasPart @shape:Section* | dct:hasPart @shape:Paragraph* ) ; under the shape shape:Chapter.

The output for Chapter:

export interface Chapter {
  "@id"?: string;
  "@context"?: ContextDefinition;
  type: {
    "@id": "Chapter";
  };
  title: string;
  referenceNumber: string;
}

Here I would expect to see something like hasPart: Section[] | Paragraph[].

megoth-capgemini commented 1 year ago

Just want to mention that the following work-around works (in case others have similar problem):

shape:Chapter EXTRA rdf:type {
  rdf:type [ selaw:Chapter ] ;
  dct:title xsd:string ;
  selaw:referenceNumber xsd:string ;
  dct:hasPart @shape:Section* ;
  dct:hasPart @shape:Paragraph* ;
}

Which outputs:

export interface Chapter {
  "@id"?: string;
  "@context"?: ContextDefinition;
  type: {
    "@id": "Chapter";
  };
  title: string;
  referenceNumber: string;
  hasPart?: (Section | Paragraph)[];
}

Is this the intended way in general?