-
Couldn't load subscription status.
- Fork 35
Raise an error when two classes have the same ambiguous attribute #352
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
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
| 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):
passand 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 <vincent.kelleher@gaia-x.eu>
ad8d5ad to
1dd9f6f
Compare
|
@cmungall @sneakers-the-rat I've just updated the pull-request with your suggestions 😇 |
|
@vincentkelleher - I don't have permission to resolve conflicts on this PR; can you check into it? |
|
@vincentkelleher I have moved the work on this PR into the repo branch github.com/linkml/linkml-runtime/tree/raise_error_for_ambiguous_attributes. If you would like to continue this work please re-open the PR on the mono-repo after the merge from that branch. We'll lift it over for you so it should take less effort. This branch will be moved over to the linkml repo with a similar name. |
|
Hi @amc-corey-cox, Thanks for notifying me 👍 I won't be working on this PR as I'm not part of Gaia-X anymore which needed this change implemented. |
Closes linkml/linkml#2403