Introducing the connect method
The add implies an active containment relationship, even though that might not be the case.
Example 1 - adding with a passive relationship:
car = my_onto.car()
engine = my_onto.engine()
car.add(engine, rel=my_onto.is_part_of) # is_part_of is a passive relationship
Problem: is_part_of is a passive relationship, therefore it is the car that is added to the engine, and not the other way around, as the user intended.
Example 2 - adding with a non-containment relationship:
alice = my_onto.person(name="Alice")
bob = my_onto.person(name="Bob")
alice.add(bob, rel=my_onto.friends_with) # friends_with is a non-containment (and symmetrical) relationship
Problem: Bob is not contained by Alice, although the user added Bob to Alice.
Proposed solution
Add a new method to the API called connect, while keeping the add method but making it throw an exception whenever a non-active relationship is used. This allows the API to be more general while reducing confusion and detecting errors.
Thank you @yoavnash for summarizing the latest discussions we had on mattermost. Here are a couple of comments ttat would be helpful as a background to this issue:
- the engine should be added to the car in example 1, why is it different?
- in EMMO, Bob would belong (be member of) the set of friends to Alice. Here we want to have a way to support - at least practically or temporarily - non EMMO compliant ontology, i.e., one that is not mereotopological in nature. the connect is then a bypass for creating the sets of friends like in the example above.
Regarding the first list item: the user wants to add the engine to the car, but what happens in fact is that the car is added to the engine (!), which is obviously not was the intent.
you mean we add the reverse relation, the engine knows about the car, but the car does not know about the engine?
Not exactly. They both know about each other, but it is the case the engine contains the car, and not the other way around.
When a cuds object is added, OSP-core adds the opposite relationship (either the passive or the active) in the other direction.
One more thought: We have the remove method that removes the relationship with another object. Similarly we have the add methods, that adds a relationship to another object. Therefore, it makes sense how it is.
In this interpretation add means adding a relationship and not adding to a container.