I think my explanation was not clear as it should be. 
I wasn't suggesting to replace the relationships with a node, but to shadow the 
relationshiptypes with a node.
Let's say we have two relationshiptypes, KNOWS and FRIEND, where we want to 
state that friends form a subset of the people a person knows. Additionally we 
have a relationshiptype SUBRELATIONSHIP indicating that a relationshiptype is a 
subtype of another relationshiptype.
For the two relationshiptypes KNOWS and FRIEND, create nodes and store the name 
of the relationshiptype in a property on that node. These two nodes must 
somehow be indexed, which you can either do with Lucene, though in my own 
application I have chosen to create a namespace node attached to the reference 
node, and create a relationship from that namespace node to the 
relationshiptype node. This allows for a quick lookup of the relationshiptype 
nodes. 
Additionally a relationhip of type SUBRELATIONSHIP should be created from the 
FRIEND node to the KNOWS node. 
Now methods for the retrieval of relationships should be written, so you don't 
fetch just the relationships with a given relationshiptype, but traverse all 
subrelationshiptype too and fetch all relationships on a node with those 
subrelationships. 
Example:
pete --> FRIEND --> jakepete --> FRIEND --> ellenpete --> KNOWS --> patty
Suppose we want to fetch all the people pete knows.
We traverse the hierarchy of relationshiptypes under KNOWS, and get an Iterable 
with the two relationshiptype nodes associated with KNOWS and FRIEND. Then we 
iterate over these relationhiptype nodes fetching the relationship on the 
pete-node with the corresponding relationshiptype, thereby returning an 
Iterable with the nodes associated with jake, ellen and patty.
For faster lookups, I have decided to use the id of the relationshiptype node 
as the name of the relationships used, but this is not a requirement for this 
solution.
Niels




> Date: Wed, 7 Dec 2011 18:16:15 +0530
> From: sourajit.ba...@gmail.com
> To: user@lists.neo4j.org
> Subject: Re: [Neo4j] Modeling subrelationships in Neo4j
> 
> To Niels' approach,
> Wouldn't it be a very dense graph ? For e.g. there will be several people
> inter-connected by KNOWS; if we model KNOWS as a node, there would be lots
> of edges originating from it.
> 
> 
> On Wed, Dec 7, 2011 at 5:16 PM, Alistair Jones <
> alistair.jo...@neotechnology.com> wrote:
> 
> > Qualifying the relationships with an additional property (or properties)
> > sounds like a sensible approach.
> >
> > The simplest thing to do would be to have a boolean property to distinguish
> > the two types, so they would both have relationship type "KNOWS", and also
> > a boolean property "well".  You could use this in a cypher query like this:
> >
> > start Alistair = node(1) match Alistair -[r:KNOWS]-> friend where r.well =
> > true return friend.name
> >
> > Alternatively, as Rick suggests, if you wanted a sliding scale of knowing,
> > you could have a numerical property, and then do more sophisticated
> > traversals.  This is analogous to a weighted graph that you might use for
> > route planning, where each of the relationships is weighted with a property
> > "distance" or "time".  In cypher:
> >
> > start Alistair = node(1) match Alistair -[r:KNOWS]-> friend where
> > r.how_well > 50 return friend.name
> >
> > This property-based approach is less sophisticated than Niels' true
> > relationship-type-hierarchy approach, but I guess it depends on your domain
> > what will be most appropriate.  I think using properties is probably
> > simpler to implement if it meets your needs.
> >
> > -Alistair
> >
> > On 6 December 2011 14:14, Rick Otten <rot...@manta.com> wrote:
> >
> > > Can you do this with properties on the relationship?
> > >
> > > In your example a "KNOWS" relationship could have a "how well" property,
> > > with values 1 to 100.
> > >
> > > You could define "KNOWS_BETTER" as  [ 50 < how well < 80 ].
> > > "KNOWS_BEST" as [ 80 <= how well <= 100 ].
> > >
> > > I'm not sure what the difference between a "sub relationship" and a
> > > "relationship qualified with properties" really is.
> > >
> > >
> > > -----Original Message-----
> > > From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org]
> > > On Behalf Of Sourajit Basak
> > > Sent: Tuesday, December 06, 2011 6:09 AM
> > > To: user@lists.neo4j.org
> > > Subject: [Neo4j] Modeling subrelationships in Neo4j
> > >
> > > Is it possible to create subrelationships in neo4j ? For e.g. a
> > > relationship called KNOWS_BETTER as a subrelationship of KNOWS.
> > >
> > > Do I need to explicitly connect the nodes using both relationships for
> > the
> > > traversal to work ? Lets say, I create this
> > >
> > > neo4j --> KNOWS_BETTER --> graphDB, does this entails the following ?
> > > neo4j --> KNOWS --> graphDB.
> > >
> > > Such a scenario can be modeled in OWL Ontology, wondering if neo4j has
> > any
> > > capabilities.
> > >
> > > Note: Under the hood, most OWL Ontology implementations do create these
> > > *extra* inferred links internally.
> > > _______________________________________________
> > > Neo4j mailing list
> > > User@lists.neo4j.org
> > > https://lists.neo4j.org/mailman/listinfo/user
> > > _______________________________________________
> > > Neo4j mailing list
> > > User@lists.neo4j.org
> > > https://lists.neo4j.org/mailman/listinfo/user
> > >
> > _______________________________________________
> > Neo4j mailing list
> > User@lists.neo4j.org
> > https://lists.neo4j.org/mailman/listinfo/user
> >
> _______________________________________________
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
                                          
_______________________________________________
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to