From 756b3f30da1f163aa32b5ab00b05a7fd99e8f496 Mon Sep 17 00:00:00 2001 From: robbe Date: Thu, 24 Apr 2025 12:27:28 +0200 Subject: [PATCH] get_slots and is_instance added to readonly api + is_instance implementation --- api/cd.py | 5 ++++- api/od.py | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/api/cd.py b/api/cd.py index d18f7b0..16168d6 100644 --- a/api/cd.py +++ b/api/cd.py @@ -53,7 +53,7 @@ class CDAPI: return self.bottom.read_outgoing_elements(self.m, type_name)[0] def is_direct_subtype(self, super_type_name: str, sub_type_name: str): - return sub_type_name in self.direct_sub_types[super_type] + return sub_type_name in self.direct_sub_types[super_type_name] def is_direct_supertype(self, sub_type_name: str, super_type_name: str): return super_type_name in self.direct_super_types[sub_type_name] @@ -83,3 +83,6 @@ class CDAPI: result = self.find_attribute_type(supertype, attr_name) if result != None: return result + + def get_type(self, type_name: str): + return next(k for k, v in self.type_model_names.items() if v == type_name) diff --git a/api/od.py b/api/od.py index c23160d..b176abf 100644 --- a/api/od.py +++ b/api/od.py @@ -143,7 +143,7 @@ class ODAPI: typ = self.cdapi.get_type(type_name) types = set(typ) if not include_subtypes else self.cdapi.transitive_sub_types[type_name] for type_of_obj in self.bottom.read_outgoing_elements(obj, "Morphism"): - if type_of_obj in types: + if self.get_name(type_of_obj) in types: return True return False @@ -262,6 +262,7 @@ def bind_api_readonly(odapi): 'get_target': odapi.get_target, 'get_source': odapi.get_source, 'get_slot': odapi.get_slot, + 'get_slots': odapi.get_slots, 'get_slot_value': odapi.get_slot_value, 'get_slot_value_default': odapi.get_slot_value_default, 'get_all_instances': odapi.get_all_instances, @@ -270,6 +271,7 @@ def bind_api_readonly(odapi): 'get_outgoing': odapi.get_outgoing, 'get_incoming': odapi.get_incoming, 'has_slot': odapi.has_slot, + 'is_instance': odapi.is_instance, } return funcs