linkml / linkml-runtime

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

Materialize structured patterns on class slot usages and attributes #204

Closed pkalita-lbl closed 2 years ago

pkalita-lbl commented 2 years ago

These changes extend the functionality of SchemaView.materalize_patterns to also include class slot usage and attributes. As a side effect it also slightly changes how structured_patterns are resolved.

Previously there was a utility method called generate_patterns which iterated over all of a schema's slots to precompute all of the resolved patterns. Then materialize_patterns would iterate over the schema's slots again and populate the schema with the results from generate_patterns.

With these changes, materialize_patterns iterates over slots and classes to account for slot_usage and attributes. In order to not duplicate logic, generate_patterns has been replaced by a class called PatternResolver which expands structured_patterns on the fly, caching results as it goes. The central logic of how the expansion is done is unchanged.

Fixes #203

pkalita-lbl commented 2 years ago

That's a good catch. I didn't think that generate_patterns would have been used outside of this project. Although, oddly that's an unused import in the linkml project. Still, you make a valid point that we shouldn't just yank away an ostensibly public function without warning. I will re-create a generate_patterns method that delegates to PatternResolver.

sujaypatil96 commented 2 years ago

The changes look good to me @pkalita-lbl.🚀 Good catch, about structured patterns not getting expanded when they are applied to slot_usage and attributes properties on classes.