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

Does't neo4j support node-set? #13455

Closed
flyly0755 opened this issue May 8, 2024 · 11 comments
Closed

Does't neo4j support node-set? #13455

flyly0755 opened this issue May 8, 2024 · 11 comments

Comments

@flyly0755
Copy link

flyly0755 commented May 8, 2024

Usually parents-child relationship with 3 nodes(father, mather, child):
fatherX---father-child_relation--->childX,
MatherX---mather-child_relation--->childX,
FatherX---huaband-wife_relation--->MatherX,

Is there super node-set conception or similar function which can combine sub-nodes?
For example: super node-set ParentX with sub-nodes fatherX and matherX, so only need just one relation with child like:
ParentX---parent-child_relation--->ChildX

And even create super node-set familiyX with sub-nodes fatherX, and matherX, ChildX and so on.

@LinneaAndersson
Copy link
Contributor

Hi @flyly0755! In neo4j a relationship must be connected to exactly 2 nodes. However, you can have multiple labels which makes it easy to "group" nodes. Let's say you want to create a mother and a father which are parent of a child. You could create two relationships like this:

CREATE (mother:Mother:Parent)-[:PARENT_OF]->(child:Child{name:"kalle"})
CREATE (father:Father:Parent)-[:PARENT_OF]->(child)

if you then would like to find both parents, you could do that with the query:

MATCH (parent:Parent)-[:PARENT_OF]-(:Child{name:"kalle"}) RETURN parent

So, you can't have more than two nodes per relationship - but you can use multiple labels for your nodes and pattern matching to find all relationships to a given node. Does this help you? Please let me know if I have misunderstood your question/feature request.

@flyly0755
Copy link
Author

flyly0755 commented May 21, 2024

@LinneaAndersson yes, a node can with multiple labels, which can be very useful.
relationship must be connected to exactly 2 nodes. -- This is a basic prerequisite.
What i think about is whether we can consider node-set concept, which can bring lots of convenience to indicate physical world include-relationship instead of point to point relationship, for example:
FamilyA contains fatherA, matherA, childA, and FamilyB contain fatherB, matherB, childB.
Assume FamilyA is a node with 3 sub-nodes(fatherA, matherA, childA),
FamilyB is a node with 3 sub-nodes(fatherB, matherB, childB), So family and member are include-relationship.
and FamilyA, FamilyB are good neighbor which is point to point relationship.

This is related with geometry(point, edge and so on), maybe what i think above is not feasible with geometry foundation:)

@LinneaAndersson
Copy link
Contributor

LinneaAndersson commented May 22, 2024

@flyly0755 Ok, now I think I understand your question/feature-request 👍

I will add it as a feature request. The only thing I can come up with that you could do today, is that you could create a node which is the node-set (in this case it would then be to create family nodes):
Screenshot 2024-05-22 at 13 56 49

Or in cypher:

CREATE (familyA:Family{name:"familyA"}),
       (familyA)-[:HAS_FAMILY_MEMBER]->(childa:Child{name:"childA"}), 
       (familyA)-[:HAS_FAMILY_MEMBER]->(mothera:Mother{name:"motherA"}),
       (familyA)-[:HAS_FAMILY_MEMBER]->(fathera:Father{name:"fatherA"}),
       (fathera)-[:PARENT_TO]->(childa),
       (mothera)-[:PARENT_TO]->(childa)
CREATE (familyB:Family{name:"familyB"}),
       (familyB)-[:HAS_FAMILY_MEMBER]->(childb:Child{name:"childB"}), 
       (familyB)-[:HAS_FAMILY_MEMBER]->(motherb:Mother{name:"motherB"}),
       (familyB)-[:HAS_FAMILY_MEMBER]->(fatherb:Father{name:"fatherB"}),
       (fatherb)-[:PARENT_TO]->(childb),
       (motherb)-[:PARENT_TO]->(childb)
CREATE (familyA)-[:IS_NEIGHBOUR_TO]->(familyB), 
       (familyB)-[:IS_NEIGHBOUR_TO]->(familyA)

@LinneaAndersson
Copy link
Contributor

Thanks for the feature request. I will close this issue now and we will let you know when we have more information. Please let me know if there is anything else we can help you with.

@LinneaAndersson
Copy link
Contributor

LinneaAndersson commented May 23, 2024

@flyly0755 does the suggested model work for your use-case? (that is: to create a node which represents the node-set) Is there something a node-set can provide than a node representing a node-set can not?

@flyly0755
Copy link
Author

@flyly0755 Ok, now I think I understand your question/feature-request 👍

I will add it as a feature request. The only thing I can come up with that you could do today, is that you could create a node which is the node-set (in this case it would then be to create family nodes): Screenshot 2024-05-22 at 13 56 49

Or in cypher:

CREATE (familyA:Family{name:"familyA"}),
       (familyA)-[:HAS_FAMILY_MEMBER]->(childa:Child{name:"childA"}), 
       (familyA)-[:HAS_FAMILY_MEMBER]->(mothera:Mother{name:"motherA"}),
       (familyA)-[:HAS_FAMILY_MEMBER]->(fathera:Father{name:"fatherA"}),
       (fathera)-[:PARENT_TO]->(childa),
       (mothera)-[:PARENT_TO]->(childa)
CREATE (familyB:Family{name:"familyB"}),
       (familyB)-[:HAS_FAMILY_MEMBER]->(childb:Child{name:"childB"}), 
       (familyB)-[:HAS_FAMILY_MEMBER]->(motherb:Mother{name:"motherB"}),
       (familyB)-[:HAS_FAMILY_MEMBER]->(fatherb:Father{name:"fatherB"}),
       (fatherb)-[:PARENT_TO]->(childb),
       (motherb)-[:PARENT_TO]->(childb)
CREATE (familyA)-[:IS_NEIGHBOUR_TO]->(familyB), 
       (familyB)-[:IS_NEIGHBOUR_TO]->(familyA)

thank you so much for your detailed explain, yeah, which is great, everything is represented as point to point relationship:)

@flyly0755
Copy link
Author

flyly0755 commented May 24, 2024

At the same time, I think of another question, the relationship between child and parents, now with neo4j is triangle model(3 points, 3 edges). But is there a new represention like T model? showed as below:

father---------mother
          |
          |
          |
         child

@LinneaAndersson
Copy link
Contributor

@flyly0755 I'm not sure I understand your question, so please let me know if I have misunderstood anything. You could create the T-model as:

 father----family-----mother
            |
            |
            |
           child

In my example above, you would do that by removing the relationships between mother-child and father-child. Note however that you would need to have four nodes:

  • Family
  • Mother
  • Father
  • Child

This because a relationship always is connected to exactly 2 nodes. So you could get a T model, but with 4 nodes. Does that answer your question?

@flyly0755
Copy link
Author

flyly0755 commented May 27, 2024

What i want to express is whether we can think out of the box:)
Now relationship can be created only between 2 nodes.
Maybe we can consider relationship between a node and a relationship.

 father<----matrimony----->mother
            |
           result 
            |
            v
           child

matrimony is relationship between father and mother intead of a node.
and result is relationship between matrimony and child.

@LinneaAndersson
Copy link
Contributor

LinneaAndersson commented May 27, 2024

@flyly0755 maybe that is something that could be done in the future, but nothing that we have any plans to do right now.

For now, you can get similar behaviour by adding a matrimony node. I'm sorry, but I can't really see why you would need a "hyper relationship" (relationship connecting to more than 2 nodes). If you have a very good use-case for it (where it's not possible to model the "hyper relationship" by adding one or more nodes), then please let me know :)

@flyly0755
Copy link
Author

yeah, hyper relationship, good concept.
For example, addition, subtraction, division and multiplication in math,
num1 (+-*/) num2 = result, so num1, num2 and result these 3 numbers relationship is hyper relationship.

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

No branches or pull requests

2 participants