owl-project / NVISII

Apache License 2.0
328 stars 28 forks source link

Improve documentation for "get_name_to_id_map" functions #52

Open natevm opened 4 years ago

natevm commented 4 years ago

It's easy to think that the following is correct:

a = entity.get_name_to_id_map()
for i,v in enumerate(a):
    entity_id = i

However! The "a" here that's returned by get_name_to_id_map is a python dictionary containing both keys as well as values. And so when doing enumerate(a), the "i" that's returned by enumerate is not the ID of the entity, but rather, some arbitrary incrementing index.

Instead, you should do:

a = entity.get_name_to_id_map()
for key, value in a.items(): 
    entity_id = key
    entity_name = value

It might be a good idea to spell this out a bit more in the documentation and/or examples.