-
Notifications
You must be signed in to change notification settings - Fork 27
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
Raise an error when two classes have the same ambiguous attribute #352
base: main
Are you sure you want to change the base?
Raise an error when two classes have the same ambiguous attribute #352
Conversation
fab66c3
to
ad8d5ad
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we extend the test to also make sure that no premature exceptions are raised when using schemaview to cycle through all slots and do a lookup (or to ensure that randomAttribute is not returned on get_slots without attributes=True)
in my opinion the problem is the ambiguity of
So I think the error message is misleading, or at least not how linkml should behave (in my opinion) - imo it should say something more like "Multiple attributes with the same name found in classes: {list of class names where attr is defined}. Access the attribute from the class directly using |
linkml_runtime/utils/schemaview.py
Outdated
@@ -631,8 +631,8 @@ def get_slot(self, slot_name: SLOT_NAME, imports=True, attributes=True, strict=F | |||
for c in self.all_classes(imports=imports).values(): | |||
if slot_name in c.attributes: | |||
if slot is not None: | |||
# slot name is ambiguous: return a stub slot | |||
return SlotDefinition(slot_name) | |||
raise ValueError(f'Attribute "{slot_name}" is already defined in another class, please use a ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be great to start making more specific exception types in these packages - super useful for downstream programming. so idk like
class AmbiguityError(ValueError):
pass
class AmbiguousNameError(AmbiguityError):
pass
and then one would both catch ValueError
's as well as having a more specific catch for that type of exception if someone wanted to (rather than needing to catch ValueError
and then check the message text to know what kind of ValueError was raised)
Thank you for your feedback 🙏 If I try to summarize everything before coding a solution:
|
Again writing from my opinion here and dont mean to hold this up - imo all the RDF generators should give URIs like
My comment here was just about the error message wording tho - it's a little unclear about what the problem is and what needs to be done: so it could say something like directed at a schema author "these attributes will be ambiguous in RDF generators and you may need to rename them or restructure the schema" or directed at a generator developer/direct user of the schema "to access these attributes use induced_slot" |
@sneakers-the-rat I think I got your point 👍 In that case we can keep the fact that it throws an exception when ambiguous attributes are found except I will write a clearer error message to push developers/ontologists to either fix the schema or use another method. If ever your attribute prefixing solution comes to fruition, we can remove this exception altogether. Is that okay for you ? |
Closes linkml/linkml#2403 Signed-off-by: Vincent Kelleher <[email protected]>
ad8d5ad
to
1dd9f6f
Compare
@cmungall @sneakers-the-rat I've just updated the pull-request with your suggestions 😇 |
Closes linkml/linkml#2403