simphony-osp icon indicating copy to clipboard operation
simphony-osp copied to clipboard

Suggestion: functionality to count contained cuds objects

Open yoavnash opened this issue 4 years ago • 9 comments

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.

yoavnash avatar Jul 02 '20 09:07 yoavnash

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.

ahashibon avatar Jul 06 '20 07:07 ahashibon

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

urbanmatthias avatar Aug 04 '20 13:08 urbanmatthias

How would you handle the case where another user adds cuds objects to a database. How would the counter of your objects be updated?

urbanmatthias avatar Aug 05 '20 06:08 urbanmatthias

How would you handle the case where another user adds cuds objects to a database. How would the counter of your objects be updated?

urbanmatthias avatar Aug 05 '20 06:08 urbanmatthias

Maybe len(cuds_object) should simply be then a call for a recursive function?

yoavnash avatar Aug 07 '20 11:08 yoavnash

The user wouldn't expect that a recursive function (that potentially takes a long time) is called with len()

urbanmatthias avatar Aug 10 '20 06:08 urbanmatthias

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.

yoavnash avatar Aug 10 '20 08:08 yoavnash

Yeah, maybe a utility function is the way to go

urbanmatthias avatar Aug 10 '20 08:08 urbanmatthias

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

yoavnash avatar Aug 10 '20 08:08 yoavnash