Skip to content

Account for any_of/exactly_one_of in get_classes_by_slot() and get_slots_by_enum() #318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions linkml_runtime/utils/schemaview.py
Original file line number Diff line number Diff line change
Expand Up @@ -1585,17 +1585,27 @@ 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:
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:
classes_set.append(c_name)

# 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:
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:
classes_set.append(c_name)

return list(classes_set)

Expand All @@ -1610,6 +1620,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)
for class_definition in self.all_classes().values():
if class_definition.slot_usage:
for slot_definition in class_definition.slot_usage.values():
Expand Down