Skip to content
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

Improved WM element (ID) handling #90

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions skiros2_common/src/skiros2_common/core/world_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,13 @@ def getIdNumber(self):
"""
@brief Return the element id number as integer
"""
if self._id.find('-') < 0:
hash_pos = self._id.find('#')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matthias-mayr I think it would be just easier to replace find with rfind :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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])

# Search after # if there is one
if hash_pos == -1:
hash_pos = 0
if self._id.find("-", hash_pos) < 0:
return -1
return int(self._id.split('-')[1])
return int((self._id[hash_pos:]).split('-')[1])

def setUri(self, eid):
self._setLastUpdate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,10 @@ def _uri2type(self, uri):
return uri.split('-')[0]

def _uri2id(self, uri):
if uri.find('-') < 0:
hash_pos = uri.find('#')
if hash_pos < 0 or uri.find("-", hash_pos) < 0:
return -1
return int(uri.split('-')[1])
return int((uri[hash_pos:]).split('-')[1])

@synchronized
def load_context(self, filename):
Expand Down