Very basic question on "how-to"

I am a brand newbie to graphs, been going through the articles, and playing around with Neo4j Desktop. I am trying to sketch out a basic model for a number of tests I have, where each test "steps" need to be considered (directional)

The one challenge I am facing is how to represent each test uniquely – so visually I can see which tests cover what nodes.

For example, let’s say I have a test Test1 which does the following “steps” - A, B, C, D, and E(sequentially in that order, so directional A-->B-->C-->D-->E
Another tests, Test2, does A-->F-->C-->D

If I consider A to F as nodes, then the directional flow is not clear – as someone can interpret that A-->F-->C-->D-->E is representing a test, when it is not.


If I tag the test “ID” as relation type, it gets messy. I also think that would be a “bad” way to model my data?

Any suggestions on how to get this in a way so that the graph shows the flow as well as distinct tests please or any articles I can read up on?

Thanks a lot in advance

This question is interesting as it doesn't use nodes and relationships the way other situations would.

I would suggest that the relationships be how you denote the tests.

Something like:

A-[:TEST1]->B-[:TEST1]->C-[:TEST1]->D-[:TEST1]->E

A-[:TEST2]->F-[:TEST2]->C-[:TEST2]->D

Hi @sridhar1971

This is another idea.

It looks complicated.

Separate processes and flows, such as when the same process appears multiple times in a flowchart.

Process: Red
Test1: Green
Test2: Gray

CREATE (a:Process {name: 'A'}),
       (b:Process {name: 'B'}),
       (c:Process {name: 'C'}),
       (d:Process {name: 'D'}),
       (e:Process {name: 'E'}),
       (f:Process {name: 'F'})
CREATE (a1:Test1 {name: 'A'}),
       (b1:Test1 {name: 'B'}),
       (c1:Test1 {name: 'C'}),
       (d1:Test1 {name: 'D'}),
       (e1:Test1 {name: 'E'})
CREATE (a1)-[:NEXT]->(b1)-[:NEXT]->(c1)-[:NEXT]->(d1)-[:NEXT]->(e1)
CREATE (a2:Test2 {name: 'A'}),
       (f2:Test2 {name: 'F'}),
       (c2:Test2 {name: 'C'}),
       (d2:Test2 {name: 'D'})
CREATE (a2)-[:NEXT]->(f2)-[:NEXT]->(c2)-[:NEXT]->(d2)
CREATE (a1)-[:IS_A]->(a),
       (b1)-[:IS_A]->(b),
       (c1)-[:IS_A]->(c),
       (d1)-[:IS_A]->(d),
       (e1)-[:IS_A]->(e)
CREATE (a2)-[:IS_A]->(a),
       (f2)-[:IS_A]->(f),
       (c2)-[:IS_A]->(c),
       (d2)-[:IS_A]->(d)

The problem you are facing is called Sequence by Neo4j, it's a commun pattern used in many graph model.

You can read about it in the Neo4j Graph Data Modeling online course here.

According to this common pattern, you have to create a parent, the Test, with two relations FIRST and LAST pointing the the first 'Lesson' and the last 'Lesson' for x Test. So this way you can have multiple Test using different sequences of sharing Lessons among different tests.

Each Lessons must have a NEXT_[LESSON_NAME] or equivalent relationship type to the next lessons.

It's a really well done course, I would highly suggest to take it if you go further in your modelling.

This picture is not the one I was looking for, you must add the parent node but it gives an idee. Here you can see NEXT_IN_PRODUCTION and NEXT as two sequences or tests sharing the same 'Lessons' or steps.

1 Like

Thanks for the responses, all! Apologies for delay in my response.

I will check out the options provided, and update here.

One method could be to branch out the nodes (in my case C1, D1) for unique test flows - in which case the directional flow will always have one (or more) underlying tests for that specific flow.

Another could be to tag the test reference (unique, say a number) to the relationships

Thoughts on these two approaches for the skeletal outline? The basic "ask" from the DB from me would be to quickly identify existing tests which cover a select number of nodes.

If the main question you want to ask is:

Which test is composed of exactly and all these x steps:

  • In the first model you will have to check at least the first hop of every test who begin by the same lesson.
  • And the second one doesn't improve the permanence so much too, but avoid duplicates and represent each test uniquely.

But in the second one, you can guess the steps of a test with the first and last steps.

So the real answer and question is : What is the scale of your project? The scale might give you which model is the best depending on how much steps, different steps sequences, tests you have.

None of them is efficient for your question if you don'y know that.