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

Fix get_classes_modifying_slot #254

Merged
merged 3 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ jobs:
# install poetry
#----------------------------------------------
- name: Install Poetry
run: pipx install poetry
# Pin to 1.3.2 to workaround https://github.com/python-poetry/poetry/issues/7611
run: pipx install poetry==1.3.2

#----------------------------------------------
# check-out repo and set-up python
Expand Down
13 changes: 6 additions & 7 deletions linkml_runtime/utils/schemaview.py
Original file line number Diff line number Diff line change
Expand Up @@ -1453,21 +1453,20 @@ def get_slots_by_enum(self, enum_name: ENUM_NAME = None) -> List[SlotDefinition]
enum_slots.append(slot_definition)
return enum_slots

def get_classes_modifying_slot(self, slot_name: SLOT_NAME = None) -> List[ClassDefinition]:
def get_classes_modifying_slot(self, slot: SlotDefinition) -> List[ClassDefinition]:
"""Get all ClassDefinitions that modify a given slot.

:param slot_name: slot in consideration
:return: list of ClassDefinitions modifying the slot of interest
"""
# slot_classes = [c for c in self.all_classes().values() if c.slot_usage == slot_name]
# slot_classes = [c for c in self.all_classes().values()]
slot_classes = []
modifying_classes = []
for class_definition in self.all_classes().values():
if class_definition.slot_usage:
for slot_definition in class_definition.slot_usage.values():
if slot_definition.name == slot_name:
slot_classes.append(class_definition)
return slot_classes
if slot_definition.name == slot.name:
modifying_classes.append(class_definition.name)

return modifying_classes

def is_slot_percent_encoded(self, slot: SlotDefinitionName) -> bool:
"""
Expand Down
12 changes: 6 additions & 6 deletions tests/test_issues/test_linkml_issue_1126.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import unittest
from unittest import TestCase
from linkml_runtime.utils.schemaview import SchemaView
from linkml_runtime.linkml_model import ClassDefinition
from linkml_runtime.linkml_model import ClassDefinitionName

from tests.test_issues.environment import env

Expand All @@ -16,13 +16,13 @@ class Issue998TestCase(TestCase):

def test_issue_1126_slot_classes(self):
view = SchemaView(env.input_path('linkml_issue_1126.yaml'))
slot_classes = view.get_classes_modifying_slot("type")
slot_definition = view.get_slot("type")
slot_classes = view.get_classes_modifying_slot(slot_definition)
assert len(slot_classes) == 2
for element in slot_classes:
assert type(element) is ClassDefinition
assert slot_classes[0].name == "Programmer"
assert slot_classes[1].name == "Administrator"

assert type(element) is ClassDefinitionName
assert slot_classes[0] == ClassDefinitionName("Programmer")
assert slot_classes[1] == ClassDefinitionName("Administrator")

if __name__ == "__main__":
unittest.main()