linkml / linkml

Linked Open Data Modeling Language
https://linkml.io/linkml
Other
297 stars 91 forks source link

Bug in Shex generator when handling enums #1513

Open deepakunni3 opened 1 year ago

deepakunni3 commented 1 year ago

Currently there seems to be an issue with the ShEx generator in linkml where enums are missed in the generated ShEx output.

To illustrate - If I have a schema as follows:

id: http://example.org/User
name: HappyUser

prefixes:
  linkml: https://w3id.org/linkml/
  example: http://example.org/
  schema: http://schema.org/
  rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#   

imports:
  - linkml:types

default_prefix: example
default_range: string

classes:
  HappyUser:
    slots:
      - status
    slot_usage:
      status:
        range: statusEnum

slots:
  status:
    description: "status"

enums:
  statusEnum:
    permissible_values:
      Happy:
          meaning: example:Happy
      Sad:
          meaning: example:Sad

Then when running gen-shex, I get the following:

prefix : <http://example.org/>

<HappyUser> CLOSED {
    (  $<HappyUser_tes> <status> @<StatusEnum> ? ;
       rdf:type [ <HappyUser> ] ?
    )
}

We see that there is a reference to StatusEnum but this is not described in the ShEx.

Ideally, we should enumerate all the permissible values for StatusEnum as follows:

prefix : <http://example.org/>

<HappyUser> CLOSED {
    (  $<HappyUser_tes> <status> [:Happy :Sad] ? ;
       rdf:type [ <HappyUser> ] ?
    )
}

This was first discovered by @labra

cmungall commented 12 months ago

@deepakunni3 is this the context for this issue? https://biohackrxiv.org/md73k/

deepakunni3 commented 12 months ago

@cmungall Yes, that is scenario where we first encountered this bug.

Upon close inspection, I noticed that the enums were not being parsed properly in the shexgen. Hence the PR. Would greatly appreciate inputs and happy to work on this further if the above fix is not sufficient in a wider scope.