Giter VIP home page Giter VIP logo

Comments (11)

LinneaAndersson avatar LinneaAndersson commented on September 21, 2024

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.

from neo4j.

flyly0755 avatar flyly0755 commented on September 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:)

from neo4j.

LinneaAndersson avatar LinneaAndersson commented on September 21, 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)

from neo4j.

LinneaAndersson avatar LinneaAndersson commented on September 21, 2024

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.

from neo4j.

LinneaAndersson avatar LinneaAndersson commented on September 21, 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?

from neo4j.

flyly0755 avatar flyly0755 commented on September 21, 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)

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

from neo4j.

flyly0755 avatar flyly0755 commented on September 21, 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

from neo4j.

LinneaAndersson avatar LinneaAndersson commented on September 21, 2024

@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?

from neo4j.

flyly0755 avatar flyly0755 commented on September 21, 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.

from neo4j.

LinneaAndersson avatar LinneaAndersson commented on September 21, 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 :)

from neo4j.

flyly0755 avatar flyly0755 commented on September 21, 2024

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.

from neo4j.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.