Skip to content

Commit

Permalink
account for any_of/exactly_one_of in get_classes_by_slot()
Browse files Browse the repository at this point in the history
  • Loading branch information
sujaypatil96 committed Apr 2, 2024
1 parent e5d1886 commit d963b4b
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions linkml_runtime/utils/schemaview.py
Original file line number Diff line number Diff line change
Expand Up @@ -1585,17 +1585,29 @@ def get_classes_by_slot(
classes_set = set() # use set to avoid duplicates
all_classes = self.all_classes()

# direct slots
for c_name, c in all_classes.items():
if slot.name in c.slots:
slot_name = slot.name
if slot_name in c.slots:
classes_set.add(c_name)
if slot.any_of or slot.exactly_one_of:
for x in slot.any_of + slot.exactly_one_of:
if x.range == c_name and slot not in classes_set:
classes_set.append(slot_name)

Check warning on line 1596 in linkml_runtime/utils/schemaview.py

View check run for this annotation

Codecov / codecov/patch

linkml_runtime/utils/schemaview.py#L1596

Added line #L1596 was not covered by tests

# add indirect slots
if include_induced:
for c_name in all_classes:
induced_slot_names = [
ind_slot.name for ind_slot in self.class_induced_slots(c_name)
]
if slot.name in induced_slot_names:
slot_name = slot.name
if slot_name in induced_slot_names:
classes_set.add(c_name)
if slot.any_of or slot.exactly_one_of:
for x in slot.any_of + slot.exactly_one_of:
if x.range == c_name and slot not in classes_set:
classes_set.append(slot_name)

Check warning on line 1610 in linkml_runtime/utils/schemaview.py

View check run for this annotation

Codecov / codecov/patch

linkml_runtime/utils/schemaview.py#L1610

Added line #L1610 was not covered by tests

return list(classes_set)

Expand All @@ -1610,6 +1622,10 @@ def get_slots_by_enum(self, enum_name: ENUM_NAME = None) -> List[SlotDefinition]
for s in self.all_slots().values():
if s.range == enum_name and s not in enum_slots:
enum_slots.append(s)
if s.any_of or s.exactly_one_of:
for x in s.any_of + s.exactly_one_of:
if x.range == enum_name and s not in enum_slots:
enum_slots.append(s)

Check warning on line 1628 in linkml_runtime/utils/schemaview.py

View check run for this annotation

Codecov / codecov/patch

linkml_runtime/utils/schemaview.py#L1628

Added line #L1628 was not covered by tests
for class_definition in self.all_classes().values():
if class_definition.slot_usage:
for slot_definition in class_definition.slot_usage.values():
Expand Down

0 comments on commit d963b4b

Please sign in to comment.