simphony-osp
simphony-osp copied to clipboard
Suggestion: functionality to count contained cuds objects
It could be useful (e.g., for statistics) to have a functionality that counts contained cuds objects inside of another cuds object or wrapper.
Implementation idea: maintain a counter in each cuds object that specifies how many nested objects are there.
good point @yoavnash for keeping the system clean, and compact in API, we can simply add a property (relation) managed by the system and accessed by get and one can also then iterate on it (e.g., on all the counts of all elements in a Data Space).
#Note:
- by system manged it is meant a "read only" (for users and admins) property. We had something like this in SimPhoNy 1.0
- ontologically, this relation would inherit (also, i.e., in multi inheritance sense) from the "ReadOnlyProperty" class
- this way we preserve the semantic meaning fully, as opposed to adding an ad hoc syntactic property outside the ontology.
Just for clarification:
- Let A has_part B and B has_part C. Then the number of contained objects of A as you propose it should be two, correct?
- Should this be available for every cuds object?
- With your proposed solution (@yoavnash) one must update the counter in potentially many cuds object in a deep tree structure, correct?
- I would rather prefer something like
len(cuds_object)
over a system managed relationship that can be queried by get, because:- it is leaner
- you cannot encode "this relationship counts the contained cuds objects" ontologically (at least not with the current formats owl and yml)
- there is no ReadOnlyProperty so far
- I like to disagree with adham ;)
How would you handle the case where another user adds cuds objects to a database. How would the counter of your objects be updated?
How would you handle the case where another user adds cuds objects to a database. How would the counter of your objects be updated?
Maybe len(cuds_object)
should simply be then a call for a recursive function?
The user wouldn't expect that a recursive function (that potentially takes a long time) is called with len()
It's either recursion when calling len()
or when calling add()
(to update the counters). Maybe we shouldn't support it then? or create a utility function that makes it clear that it uses recursion.
Yeah, maybe a utility function is the way to go
Maybe we should make a module called rec
or recursive
to mark all the recursive functionalities explicitly as recursive. As an illustration:
from osp.core.utils.rec import pretty_print, count