GraphGist: Preview

[Warning]Warning

This GraphGist has not yet been submitted and approved for publication. If you're the developer, please submit for publication using the GraphGist Portal.

This gist is to complement the more elaborate blogpost that I wrote about using neo4j to model the partlist and the assembly process of two IKEA wardrobes.

First, we will create a part of the graph using this model:

// create the nodes

create
(shoparticle{id:'1',name:'ShopArticle',type:'ShopArticle'}),
(screw{id:'112996',name:'Screw',type:'Component'}),
(nail{id:'124593',name:'Nail',type:'Component'}),
(left{id:'10',name:'Sidepanel left',type:'StructureComponent'}),
(right{id:'11',name:'Sidepanel right',type:'StructureComponent'}),
(top{id:'12',name:'Top',type:'StructureComponent'}),
(bottom{id:'13',name:'Bottom',type:'StructureComponent'}),
(screwdriver{id:'100',name:'Screwdriver Cross',type:'Tool'}),
(hammer{id:'103',name:'Hammer',type:'Tool'}),
(processone{id:'1001',name:'Step 1',type:'Process Step'}),
(processtwo{id:'1002',name:'Step 2',type:'Process Step'}),
(processthree{id:'1003',name:'Step 3',type:'Process Step'}),

// create the relationships

shoparticle-[:USES_COMPONENT{quantity:12}]->screw,
shoparticle-[:USES_COMPONENT{quantity:40}]->nail,
shoparticle-[:USES_STRUCTURE_COMPONENT{quantity:1}]->left,
shoparticle-[:USES_STRUCTURE_COMPONENT{quantity:1}]->right,
shoparticle-[:USES_STRUCTURE_COMPONENT{quantity:1}]->top,
shoparticle-[:USES_STRUCTURE_COMPONENT{quantity:1}]->bottom,
shoparticle-[:STARTS_CONSTRUCTION]->processone,
processthree-[:COMPLETES_CONSTRUCTION]->shoparticle,
processtwo-[:STARTS_PROCESS{quantity:4}]->screw,
processtwo-[:USES]->screwdriver,
screw-[:CONNECT_TO{quantity:4}]->left,
left-[:ENDS_PROCESS]->processtwo,
processone-[:CONTINUES_PROCESS]->processtwo,
processtwo-[:CONTINUES_PROCESS]->processthree;

The actual graph then looks like this:

Loading graph...

Then we can actually start doing some queries, like for example: Give me the total partlist for a shoparticle

START
	shoparticle=node:node_auto_index(type="ShopArticle")
match
	component<-[:USES_STRUCTURE_COMPONENT|USES_COMPONENT]-shoparticle
return
	shoparticle.name as Item, component.name as Component, component.type
order by component.type;
Loading table...

Or let’s try this one: Give me the number of installation steps for every ShopArticle:

START
	shoparticle=node:node_auto_index(type="ShopArticle")
MATCH
	p = (shoparticle)-[:STARTS_CONSTRUCTION]->(step)-[:CONTINUES_PROCESS*]->(step2)-[:COMPLETES_CONSTRUCTION]->(shoparticle)
RETURN
	shoparticle.name AS Item, (length(p)-1) AS NumberOfSteps;
Loading table...

As you can see from the path query below, this is indeed the case:

START shoparticle=node:node_auto_index(type="ShopArticle")
MATCH p =(shoparticle)-[:STARTS_CONSTRUCTION]->(step)-[:CONTINUES_PROCESS*]->(step2)-[:COMPLETES_CONSTRUCTION]->(shoparticle)
RETURN p;
Loading graph...

To play some more, use the console below. Enjoy!

Running queries, preparing the console!

Run
Table
Graph
Table!
Graph!
Error!
Loading