Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add multi-hop support to RelationshipDefinition #635

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

AntonLydike
Copy link
Collaborator

@AntonLydike AntonLydike commented Aug 13, 2022

I want to add support for multiple-hop relationship definitions. For example:

class Person(StructuredNode):
  name = StringProperty()
  
  parent = RelationshipTo('Person', 'PARENT')
  ancenstors = RelationshipTo('Person', 'PARENT', n_hops='*')
  decendants = RelationshipFrom('Person', 'PARENT', n_hops='*')
  grandchildren = RelationshipFrom('Person', 'PARENT', n_hops=2)
  # it should also support ranges such as '2..4' or '1..' (one or more)

I am open for ideas and pointers!

@AntonLydike
Copy link
Collaborator Author

AntonLydike commented Aug 13, 2022

Question: How to best handle calls to connect(), disconnect(), reconnect(), etc?

I have added a property called allows_creation which marks if this relationship manager is allowed to create edges. The code then checks for this whenever necessary, and if it isn't allowed to create an edge, it throws a NotImplementedError (this type is probably improvable!)

The intended behavior for disconnect and disconnect_all is now to delete the whole path. I am unsure if it is desirable to have such a foot gun though.

@AntonLydike
Copy link
Collaborator Author

The allows_creation property could then be used to make re-implementing #533 way easier as this ran into similar issues back then.

@aanastasiou
Copy link
Collaborator

@AntonLydike

A few thoughts in no particular order:

  1. You propose a Relationship type that can include more than one edges.

  2. In a typical Neo4j database, the underlying property graph is assumed to be a Multigraph. The only thing that Multigraphs add is the ability to have more than one edge between any two nodes.

  3. A Relationship that spans more than one nodes is akin to a hyper-edge in a hypergraph.

  4. A neomodel Relationship does not have hyper-edge semantics.

  5. While it is possible to model hyper-edges in Neo4j, I would be hesitant in trying to lump hyper-edges with Relationships.

    • For example, Neo4j includes the concept of a path but that is not a primitive data type throughout CYPHER. Node connections (from the point of view of a data type) are still assumed to be edges with properties that link always two nodes.
    • Furthermore, the example you provide here assumes that all segments of a hyper-edge (all the "hops" of a "Relationship") are supposed to have the same property model (the same Relationship class definition). This is not always the case. A hyper-edge with properties can have different attributes at its segments. It is an entirely different data type.

Therefore, I would like to propose the following:

  • Neomodel could include a contrib entity to model hyper-edges. This entity would have to be a new type. This new type could possibly inherit from Relationship but also include all the functionality that is required of hyper-edges.

  • To decide what functionality should be assigned to hyper-edges, you should have one or more motivating use-cases.

    • Here for example, your motivating use case seems to be being able to address a set of nodes with specific characteristics given a starting node. In my mind, this still sounds like it would be better served via a query. But you may have come across a use-case that indicates otherwise. We need to see the use-cases and the examples before setting off to incorporate this in neomodel.

My perception is that this feature needs more thinking before we can consider a PR, but I am happy to think twice :)

@aanastasiou aanastasiou added feature Describes a new feature and removed review_to_be_done labels May 22, 2023
@sonarcloud
Copy link

sonarcloud bot commented Jul 20, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 10 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Describes a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants