Fix bug where creation of slot defined in super-class fails + clearer error message
This commit is contained in:
parent
6cd8bbb8cc
commit
98ae637eea
2 changed files with 7 additions and 5 deletions
|
|
@ -35,7 +35,7 @@ class Conformance:
|
||||||
self.scd_model = UUID(state.read_value(type_model_id))
|
self.scd_model = UUID(state.read_value(type_model_id))
|
||||||
self.model = model
|
self.model = model
|
||||||
self.type_model = type_model
|
self.type_model = type_model
|
||||||
self.constraint_check_subtypes = constraint_check_subtypes # for a class-level constraint, also check the constraint on the subtypes of that class?
|
self.constraint_check_subtypes = constraint_check_subtypes # for a class-level constraint, also check the constraint on the subtypes of that class? In other words, are constraints inherited.
|
||||||
self.type_mapping: Dict[str, str] = {}
|
self.type_mapping: Dict[str, str] = {}
|
||||||
self.model_names = {
|
self.model_names = {
|
||||||
# map model elements to their names to prevent iterating too much
|
# map model elements to their names to prevent iterating too much
|
||||||
|
|
|
||||||
|
|
@ -69,9 +69,11 @@ class OD:
|
||||||
def create_slot(self, attr_name: str, object_name: str, target_name: str):
|
def create_slot(self, attr_name: str, object_name: str, target_name: str):
|
||||||
class_name = self.get_class_of_object(object_name)
|
class_name = self.get_class_of_object(object_name)
|
||||||
attr_link_name = self.get_attr_link_name(class_name, attr_name)
|
attr_link_name = self.get_attr_link_name(class_name, attr_name)
|
||||||
|
if attr_link_name == None:
|
||||||
|
raise Exception(f"Failed to get link name for attribute '{attr_name}' of object '{object_name}'")
|
||||||
# An attribute-link is indistinguishable from an ordinary link:
|
# An attribute-link is indistinguishable from an ordinary link:
|
||||||
slot_id = self.create_link(
|
slot_link_name = get_slot_link_name(object_name, attr_name)
|
||||||
get_slot_link_name(object_name, attr_name),
|
slot_id = self.create_link(slot_link_name,
|
||||||
attr_link_name, object_name, target_name)
|
attr_link_name, object_name, target_name)
|
||||||
return slot_id
|
return slot_id
|
||||||
|
|
||||||
|
|
@ -154,9 +156,9 @@ class OD:
|
||||||
return assoc_name
|
return assoc_name
|
||||||
else:
|
else:
|
||||||
# look for attribute in the super-types
|
# look for attribute in the super-types
|
||||||
conf = Conformance(self.bottom.state, self.type_model, get_scd_mm(self.bottom))
|
conf = Conformance(self.bottom.state, self.model, self.type_model)
|
||||||
conf.precompute_sub_types() # only need to know about subtypes
|
conf.precompute_sub_types() # only need to know about subtypes
|
||||||
super_types = (s for s in conf.sub_types if class_name in conf.sub_types[s])
|
super_types = [s for s in conf.sub_types if class_name in conf.sub_types[s]]
|
||||||
for s in super_types:
|
for s in super_types:
|
||||||
assoc_name = f"{s}_{attr_name}"
|
assoc_name = f"{s}_{attr_name}"
|
||||||
if len(self.bottom.read_outgoing_elements(self.type_model, assoc_name)) == 1:
|
if len(self.bottom.read_outgoing_elements(self.type_model, assoc_name)) == 1:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue