The implementation of HyperRelationships needs another day of work, though the 
hard parts are finished now.

Time to explain the inner workings of HyperRelationships.

HyperRelationships are a generalization of the binary relationships found in 
Neo4j. 

Instead of creating a relationship from a node to another node, 
we define a HyperRelationship as a set of Nodes each having a RelationshipRole 
within the HyperRelationship.

For the binary case the RelationshipRoles are StartNode and EndNode. 
For HyperRelationships with an arity higher than 2, the Roles need to be 
defined for each HyperRelationshipType.

A HyperRelationship is layed-out in the database as a regular relationship in 
the binary case.

For HyperRelationship with an arity higher than 2, a Node is created subsuming 
the role of Relationship. 
>From this Node, binary relationships (regular Neo4J relationships) are created 
>for each Element of the relationship. 

The RelationshipTypes of these binary relationships are a concatenation of the 
name of the HyperRelationshipType used 
and the RelationshipRole of the attached Element.

Example: 

Suppose we want to store the fact that Flo and Eddie give Tom, Dick and Harry a 
Book.

This is a ternary relationship, with the following RelationshipRoles:

Giver: Flo and Eddie
Recipient: Tom, Dick and Harry
Gift: Book

The GIVE relationship is first created with a Set of Roles (Giver, Recipient 
and Gift). 
When the example relation is created the following binary relationships will be 
create:

HyperRelationshipNode --GIVE/#/Giver--> Flo
HyperRelationshipNode --GIVE/#/Giver--> Eddie
HyperRelationshipNode --GIVE/#/Recipient--> Tom
HyperRelationshipNode --GIVE/#/Recipient--> Dick
HyperRelationshipNode --GIVE/#/Recipient--> Harry
HyperRelationshipNode --GIVE/#/Gift--> Book

We can now retrieve all Relationships where Flo is the Giver in a GIVE 
relationship, 
simply by concatenating GiVE and Giver into GIVE/#/Giver, 
and then ask all incoming Relationships with that RelationshipType. 

This fetches the HyperRelationship nodes and the other attached Elements of the 
HyperRelationship can be loaded.

I added an extra interface FunctionalRelationshipRole, which restricts the 
number of Elements attached to a RelationshipRole within a HyperRelationship to 
one.

The use of this amounts to something similar to having a getSingleRelationship 
method, 
which cannot throw an Exception, because multiple entries with the same 
RelationshipType cannot be created by design.

Niels
> From: [email protected]
> To: [email protected]
> Date: Mon, 25 Jul 2011 02:03:54 +0200
> Subject: [Neo4j] Enhanced API and HyperRelationships
> 
> 
> Today I wrote a piece about the Enhanced API and about HyperRelationships, I 
> have been working on over the last couple of days.
> 
> See: https://github.com/peterneubauer/graph-collections/wiki/Enhanced-API
> 
> The API as presented in the graph-collections repo on Git is not feature 
> complete yet with respect to HyperRelationships. 
> The interfaces are there, but the implementation only works for binary 
> relationships at present. Need one more day for the implementation.
> 
> I posted the Wiki page and the source code to open the discussion about these 
> new features.
> 
> Niels                                           
> _______________________________________________
> Neo4j mailing list
> [email protected]
> https://lists.neo4j.org/mailman/listinfo/user
                                          
_______________________________________________
Neo4j mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to