Skip to content
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

Optimize get_classes_by_slot round 2 #304

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
21 changes: 9 additions & 12 deletions linkml_runtime/utils/schemaview.py
Original file line number Diff line number Diff line change
Expand Up @@ -1542,19 +1542,16 @@ def get_classes_by_slot(
:return: list of slots, either direct, or both direct and induced
"""
classes_set = set() # use set to avoid duplicates
all_classes = self.all_classes()

for c_name, c in all_classes.items():
if slot.name in c.slots:
classes_set.add(c_name)

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:
for c_name, c in self.all_classes().items():
if include_induced:
for c_slot in self.class_slots(c_name):
if slot.name == c_slot:
classes_set.add(c_name)
break
else:
if slot.name in c.slots:
classes_set.add(c_name)
break

return list(classes_set)

Expand Down
Loading