Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -67,11 +67,11 @@ def lightstring2uri(self, name):
if name == "":
return None
if name.find("#") > 0:
return name
return rdflib.term.URIRef(name)
if name.find(":") < 1:
if name.find(":") == 0:
name = name[1:]
return self.add_default_prefix(name)
return rdflib.term.URIRef(self.add_default_prefix(name))
tokens = name.split(":")
for prefix, uri in self._ontology.namespaces():
if tokens[0] == prefix:
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