4
votes

I am looking into using a graph db for a project that will require the modelling of relationships between relationships. For example a tie between A and B may be conditional on a tie between C and D.

I also need to model relationships between nodes and other relationships. Catalytic relationships may be a good example. Agent X accelerates the relationship between agents Y and Z. The relationships need to contain properties that describe the relationship.

I can produce a relational db to achieve this by making nodes and relationships inherit from the same type. So a table per type database structure has the primary key in the BaseType table and a one to one relationship with sub-type tables: Node and Relationship. The Relationship table then has three foreign keys to the BaseType table. One is its primary key and the other two make up the Source and Target of the relationship. One or both of the source and target can therefore be Relationship types.

But this contains many joins of small objects, which fits the description of databases that should perform best with a Graph DB.

Diagrams as requested - including an attempted solution.

A-B relationship influences the C-D relationship

Catalytic relationship between four agents

My attempt to solve the problem by creating relationship nodes.

Possible solution to catalyst relationship

Possible solution to relationships influencing other relationships

So the solution I propose here involves creating more nodes. I suppose this could work, but wonder whether I am making it unnecessarily complicated.

One final diagram - the relational db solution. This seems a little cleaner, but not as flexible as the Graph db approach. And perhaps not as efficient? enter image description here

2
Please show the example as a diagramAravind Yarram

2 Answers

1
votes

Your approach to modelling an "edge with edges" by adding nodes/vertices to resolve those connecting relationships makes sense. For graph databases that expose a Property Graph Model (like Neo4j, Titan and other Blueprints-enabled graphs), that simulation of a hypergraph is the right way to get that functionality. There's an ongoing discussion in the gremlin-users mailing list that is discussing this topic now in the context of Blueprints...you can read it here.

0
votes

You can solve the problem of using an hypergraph built ontop of graph database.

Or you can use a RDF database. RDF database is a set of 4-tuples that look like the following:

(graph, subject, predicate, object)

You can relate to mongodb-like collection based abstractions using the following nomaneclautre:

(collection, object_id, field, value)

The different is that since the RDF database is a set, you can have several tuples with the same field that is the following is valid in most RDF databases:

(wikipedia, P4X432, title, "Resource Description Framework")
(wikipedia, P4X432, see-also, "RSS")
(wikipedia, P4X432, see-also, "Dublin Core")

In most RDF databases; tuple items can be any string and sometime they can be float etc... Sometime, the tuple items are URI. Anyway for the purpose of that question let's forget about URI.

So you have the following data:

  • A friend B
  • C friend D

You model it in RDF database as follow:

(f1, A, friend, B)
(f2, C, friend, D)

If you can add the following tuple to express that frienship between C and D is influcend by friendship between A and B:

(f3, f1, influence, f2)