[Neo] Choosing between a property or a node

rick.bullotta at burningskysoftware.com rick.bullotta at burningskysoftware.com
Fri Feb 19 13:24:21 CET 2010


   Mattias (and everyone) - can you see a way to model multiple
   relationships of the same type between two nodes?  We have  few cases
   where the relationship is essentially the same "type" but might have
   different properties.  Max's "Class/Teacher" scenario is
   somewhat similar.



   Rick



   -------- Original Message --------
   Subject: Re: [Neo] Choosing between a property or a node
   From: Mattias Persson <mattias at neotechnology.com>
   Date: Fri, February 19, 2010 4:27 am
   To: Neo user discussions <user at lists.neo4j.org>
   I've included some first thoughts on how you could model this. The
   choice of properties/index vs. relationships is often quite obvious,
   but is some cases you'll have to try and see which fits best. But
   neo4j encourages you to create relationships if you're in doubt and
   it's often better to use more relationships types than fewer, i.e.
   it's good to be as specific as possible when modelling your graph.
   2010/2/19 Max De Marzi Jr. <maxdemarzi at gmail.com>:
   > Hello,
   >
   > What is the proper way to handle things that have only a few choices
   like:
   >
   > gender (male/female/unknown)
   > status (active, inactive, purged)
   > race(10 choices + other)
   > etc.
   >
   > As properties of a Person node, or as nodes that link to the Person
   node?
   >
   > Pros or Cons of each method?
   It depends on how you're querying the data... gender, status and race
   could probably be modelled using properties (and maybe indexed with
   IndexService, see [1]http://components.neo4j.org/neo4j-index/) since
   you
   would use them as filters in queries. But if you're planning to do
   traversals which will bridge persons over to other persons (or other
   entities) via f.ex. status, then relationships would be handier.
   >
   > How about something with instances?
   >
   > Student took a Class (twice) once with This teacher, once with
   Another
   > Teacher.
   >
   > The first time he failed, the second time he got a B.
   >
   > Create a StudentClass node with a property of Grade, linked to
   Teacher?
   Yes, have each student as a node. Each class instance as a node with
   TEACHES_IN relationship to teacher (and maybe CLASS_TYPE relationship
   to what type of class the class instance is). Have a TAKES_CLASS
   relationship between student and class instance and set grade property
   on that relationship.
   >
   > In order to answer:
   >
   > Find all students who took the class.
   Relationships between student and class.
   > Find all students who took the class when it was offered in the
   spring
   > semester (or taught by This Teacher).
   Start from either a teacher node (and go to the class instance) or
   from a class instance. They can be lookup up from and IndexService or
   something) and get relationships to students from there.
   > Find all students who got a B
   If you create nodes for each grade available and create relationships
   to those grade nodes whenever a student gets a grade. Then it'd be
   easy to just get that "B" grade node and traverse all its
   relationships to students. Otherwise you could index the grade
   property from the ATTEND_CLASS relationships (see above) for the
   student nodes.
   > Find all students to got a B in this class?
   Start from the class and traverse out to all its class instances and
   students, filtering those who got a B (using the grade property on
   ATTEND_CLASS relationships).
   > Find all students to got a B in this class during the spring
   semester?
   Same as previous but only traverse those class instances which were
   offered in spring semester.
   > Find all students to got a B in this class when This Teacher taught
   it?
   Start from either the teacher node or the class node and find the
   class instance for that class which the teacher has a relationship to.
   And tou get the students from there.
   I hope this will help you,
   Best,
   Mattias
   _______________________________________________
   Neo mailing list
   User at lists.neo4j.org
   [2]https://lists.neo4j.org/mailman/listinfo/user

References

   1. http://components.neo4j.org/neo4j-index/
   2. https://lists.neo4j.org/mailman/listinfo/user


More information about the User mailing list