Open
Conversation
Previously this function could return strings, which caused an instance check in rdflib to fail with "must be an rdflib term".
Previously obtaining the ID of URI's like: "http://www.inf.ufrgs.br/phi-group/ontologies/cora.owl#Robot-186" Failed, because it was assumed that "-" only appears once in the URI. Now it searches only after the hash "#" if one exists
Member
Author
|
wrong mention @frvd |
frvd
suggested changes
Feb 19, 2024
| @brief Return the element id number as integer | ||
| """ | ||
| if self._id.find('-') < 0: | ||
| hash_pos = self._id.find('#') |
Contributor
There was a problem hiding this comment.
@matthias-mayr I think it would be just easier to replace find with rfind :)
Member
Author
There was a problem hiding this comment.
rfind for the "-" or the "#"? Assume the former since the latter does not seem to make any sense to me
However just using rfind for the "-" does not necessarily yield to the expected result.
Example:
A malformed URI like http://www.inf.ufrgs.br/phi-group/ontologies/cora.owl#Robot that does not have an ID should lead to a return value of "-1" according to the previous/other code.
That's why I wanted to search explicitly after the hash if there's one
Contributor
There was a problem hiding this comment.
Right, what about the following?
hash_pos = self._id.rfind('#')
dash_pos = self._id.rfind("-")
return -1 if dash_pos == -1 or dash_pos < hash_pos else int(self._id.split('-')[1])
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When testing, I ran into two issues that are addressed in this PR.
lightstring2urimethod could return a string instead of an rdflibURIRef. This caused errors of this kind:Since we have URIs like
http://www.inf.ufrgs.br/phi-group/ontologies/cora.owl#Robot-1, this could lead to errors like:This two commits address both. However, I am not sure if they would cause side effects.
@frovida: If you have sth to comment, please do so.
I will merge them into the ROS 2 branch, so they would get some sort of testing.
This also came up when "reviving" the skiros2_test_lib. Once it's fully up, we can also make changes with some more confidence.