linkml / linkml-runtime

Runtime support for linkml generated models
https://linkml.io/linkml/
Creative Commons Zero v1.0 Universal
24 stars 23 forks source link

`SchemaView.materialize_patterns()` does not account for `slot_usage` #203

Closed pkalita-lbl closed 2 years ago

pkalita-lbl commented 2 years ago

If I have a schema that contains the following:

# test.yaml
settings:
  generated_id: "[a-z0-9]{6,}"

classes:
  MyClass:
    slots:
      - id

slots:
  id:
    structured_pattern:
      syntax: "prefix:{generated_id}"

And I call the materialize_patterns method on a SchemaView instance for that schema, I see that the pattern meta-slot is populated as expected:

>>> from linkml_runtime import SchemaView
>>> view = SchemaView('test.yaml')
>>> view.schema.slots['id'].pattern is None
True
>>> view.materialize_patterns()
>>> view.schema.slots['id'].pattern
'prefix:[a-z0-9]{6,}'

However if the structured_pattern is instead set on the slot_usage of a class:

# test2.yaml
settings:
  generated_id: "[a-z0-9]{6,}"

classes:
  MyClass:
    slots:
      -id
  FancyIdClass:
    is_a: MyClass
    slot_usage:
      id:
        structured_pattern:
          syntax: "prefix:{generated_id}"

slots:
  id:

Calling materialize_patterns on the SchemaView instance doesn't seem to have any effect. I suppose I would expect the pattern to be materialized on the slot_usage definition instead in this case.

>>> view = SchemaView('test2.yaml')
>>> view.schema.classes['FancyIdClass'].slot_usage['id'].pattern is None
True
>>> view.materialize_patterns()
>>> # I think I would expect this to not be None at this point
>>> view.schema.classes['FancyIdClass'].slot_usage['id'].pattern is None
True
cmungall commented 2 years ago

This makes sense, on attributes too.