This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= IKEA GraphGist = | |
This gist is to complement the http://blog.bruggen.com/2013/09/ikea-wardrobes-and-graphs-perfect-fit.html[more elaborate blogpost] that I wrote about using http://neo4j.org[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: | |
image::https://lh4.googleusercontent.com/7XxUuCjnFtDhO-JAI5Ia6tcYZkQoMfcv_1pNE0mTA2cx76vIySrBU0z0tnykAPvqsMrZZD-cca3Q7ca-ERI0f5sDsGAUCEJTIx7wt15mxKhFEXeYFrZD_vEGJQ[] | |
[source,cypher] | |
---- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this script uses the neo4j-shell-tools | |
// create personal nodes | |
import-cypher -d ; -i ./IMPORT/INPUT/PersonalNodes.csv -o ./IMPORT/OUTPUT/personalnodeout.csv create (n:url {id:{id}+1000,name:{name},type:{type}}) return n.name as name | |
// create indices | |
CREATE index on :url(name); | |
CREATE index on :url(id); | |
CREATE index on :url(type); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= Presenting Neo4j GraphGist = | |
This gist is to complement the http://blog.bruggen.com/[more elaborate blogpost] that I wrote how the http://www.prezi.com[prezi] presentation style actually massively resembles a graph. And how you could actually create a graph about http://neo4j.org[neo4j] to explain what graph databases are all about. | |
[source,cypher] | |
---- | |
// create the nodes | |
create (n1{id:'1', name:'Neo4j', type:'Product', comments:''}), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create indices and constraints | |
CREATE CONSTRAINT ON (n:Station) ASSERT n.name IS UNIQUE; | |
// create nodes | |
// create Stations | |
import-cypher -d ; -i ./IMPORT/INPUT/isdb.csv -o ./IMPORT/OUTPUT/nodeoutput.csv merge (n:Station {name:{StationA}}) return n | |
import-cypher -d ; -i ./IMPORT/INPUT/isdb.csv -o ./IMPORT/OUTPUT/nodeoutput.csv merge (n:Station {name:{StationB}}) return n | |
//create rels | |
import-cypher -d ; -i ./IMPORT/INPUT/isdb.csv -o ./IMPORT/OUTPUT/rel.csv MATCH (stationa:Station {name:{StationA}}), (stationb:Station {name:{StationB}}) CREATE stationa-[r:#{Line} {direction:{Direction}, distance:{Distance}, time:{Time}}]->stationb RETURN r |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Run these queries in the neo4j-shell or the neo4j-browser to see the database at work. | |
// | |
//Show the datamodel: what is related to what, and how? | |
MATCH (a)-[r]->(b) | |
RETURN DISTINCT head(labels(a)) AS This, type(r) AS To, head(labels(b)) AS That | |
LIMIT 100 | |
//Which labels are there and how many nodes have that label? | |
MATCH n RETURN labels(n), count(n); | |
//Which relationship types are there and how many rels are there of that type? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= Untying the Graph Database Import Knot = | |
This Graphgist accompanies http://blog.bruggen.com/2013/12/untying-graph-database-import-knot.html[my blogpost of December 6th, 2013] which tries to explain the different types of questions that people should be asking themselves when thinking about importing data into http://www.neo4j.org[neo4j], and the tools that can contribute to finding the most optimal import strategy for your specific use case. | |
//setup | |
//hide | |
[source,cypher] | |
---- | |
create (n1:Tool {id:'1',name:'Spreadsheets'}), | |
(n2:Tool {id:'2',name:'Cypher Statements'}), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create nodes | |
// create BaseNodes | |
import-cypher -d ; -i ./IMPORT/INPUT/1-basenodes.csv -o ./IMPORT/OUTPUT/nodeoutput.csv create (n:#{type} {id:{id},name:{name}}) return n | |
// create indexes | |
create index on :INGREDIENT_CATEGORY(name); | |
create index on :INGREDIENT(name); | |
create index on :INGREDIENT(id); | |
create index on :COMPOUND(name); | |
create index on :COMPOUND(id); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= Open Source Licensing Graph = | |
This gist is explain the Open Source Licensing Graph, based on the wonderful data from http://choosealicense.com/[ChoosALicense.com], a http://www.github.com[github] service. I wrote a small blogpost around it too on http://blog.bruggen.com/2014/01/the-open-source-licensing-graph.html[my blog]. | |
First we have to load the data into the graph. This was a bit of work - but not difficult at all: | |
//hide | |
//setup | |
//output | |
[source,cypher] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Total number of visits by guests to shows | |
match (g:GUEST)-[v:VISITED]->(sh:SHOW) | |
return count(v); | |
//Number of visits by show | |
match (g:GUEST)-[v:VISITED]->(sh:SHOW) | |
return sh.id as Show, count(v) as NrOfVisits | |
order by NrOfVisits desc; | |
//Number of Politicians by show |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Let's create the top of the tree, the PRODUCT | |
create (n1:PRODUCT {id:1}); | |
//Let's create 100 children of the PRODUCT, COST_GROUPS connected to the top of the tree | |
match (n1:PRODUCT {id:1}) | |
with range(1,100) as RANGE, n1 | |
foreach (r in RANGE | create (n2:COST_GROUP {id:r})-[:PART_OF {quantity:round(rand()*100)}]->(n1) ); | |
//for every COST_GROUP, let's connect 100 children at a 3rd level, the COST_TYPEs | |
match (n2:COST_GROUP) |