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

Creating an ObjectIndex, fixes https://github.com/linkml/linkml/issues/1009 #211

Closed cmungall closed 2 years ago

cmungall commented 2 years ago

Given a tree-root/container object, this will create an index, and allow for retrieval of proxy objects that shadow domain YAMLRoot classes. These operate in the same way, except that object references are automatically dereferenced.

For example, given a container object following the standard
personinfo schema, an index can be created and queried:

    >>> ix = ObjectIndex(container, schemaview=schemaview)
    >>> container = ix.bless(container)
    >>> for p in container.persons:
    >>>    for r in p.has_familial_relationships():
    >>>        print(f"{p.name} {p.type} {r.related_to.name}")

Note this will work even if related_to is *not* inlined.

This means naive traversal of the object tree is not guaranteed
to be bounded, unlike with a YAMLRoot object. E.g.

    >>> person.has_familial_relationships[0].
    >>>    related_to.has_familial_relationships[0].
    >>>    related_to.has_familial_relationships[0].name

In the above, the same proxy object is reused for any
object with an identifier.
codecov-commenter commented 2 years ago

Codecov Report

Merging #211 (40ed5dd) into main (7a53613) will decrease coverage by 0.90%. The diff coverage is 56.48%.

@@            Coverage Diff             @@
##             main     #211      +/-   ##
==========================================
- Coverage   63.33%   62.43%   -0.91%     
==========================================
  Files          50       52       +2     
  Lines        5501     5997     +496     
  Branches     1567     1697     +130     
==========================================
+ Hits         3484     3744     +260     
- Misses       1598     1791     +193     
- Partials      419      462      +43     
Impacted Files Coverage Δ
linkml_runtime/linkml_model/annotations.py 90.38% <ø> (ø)
linkml_runtime/linkml_model/extensions.py 85.45% <ø> (ø)
linkml_runtime/linkml_model/mappings.py 0.00% <ø> (ø)
linkml_runtime/linkml_model/types.py 100.00% <ø> (ø)
linkml_runtime/linkml_model/validation.py 0.00% <0.00%> (ø)
linkml_runtime/utils/introspection.py 68.75% <37.50%> (-31.25%) :arrow_down:
linkml_runtime/utils/csvutils.py 84.61% <40.00%> (-1.50%) :arrow_down:
linkml_runtime/linkml_model/meta.py 52.74% <52.27%> (+<0.01%) :arrow_up:
linkml_runtime/linkml_model/units.py 76.00% <76.00%> (ø)
linkml_runtime/utils/pattern.py 88.57% <85.18%> (+2.85%) :arrow_up:
... and 12 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.