Skip to content

Instantly share code, notes, and snippets.


Rik Van Bruggen rvanbruggen

View GitHub Profile
View hierarchy graphgist
= (Product) Hierarchy GraphGist =
This gist is a complement to[blogpost that I wrote] about managing hierarchical data structures in[neo4j]..
In this example, we are using a "product hierarchy", essentially holding information about the composition of a product (what is it made of, how many of the components are used, and at the lowest level, what is the price of these components). The model looks like this:
Note that in the graphgist, I have cut the tree depth to 5 levels (product to costs) instead of 6 in the blogpost - and that I also reduced the width of the tree to make it manageable in a gist.
rvanbruggen / thuis.cql
Last active Aug 29, 2015
Thuis GraphGist
View thuis.cql
= The Belgian Sitcom Graph: Who's Hot in "Thuis" =
This gist is going to show you how you can query the elaborate landscape of relationships in[Thuis]. It is based on this picture by[@pieter_vh]. Very well done actually.
I took the picture and created a spreadsheet version of it - take a look[over here]. That allowed me to create the graph, which we will also setup in this Gist:
View Creating Dem Bones
//create them bones
create (_0:`LEG`:`BONES` {`condition`:"dry", `id`:1, `name`:"toe bone", `side`:"left", `subname`:1})
create (_1:`LEG`:`BONES` {`condition`:"dry", `id`:2, `name`:"toe bone", `side`:"left", `subname`:2})
create (_2:`LEG`:`BONES` {`condition`:"dry", `id`:3, `name`:"toe bone", `side`:"left", `subname`:3})
create (_3:`LEG`:`BONES` {`condition`:"dry", `id`:4, `name`:"toe bone", `side`:"left", `subname`:4})
create (_4:`LEG`:`BONES` {`condition`:"dry", `id`:5, `name`:"toe bone", `side`:"left", `subname`:5})
create (_5:`LEG`:`BONES` {`condition`:"dry", `id`:6, `name`:"toe bone", `side`:"right", `subname`:1})
create (_6:`LEG`:`BONES` {`condition`:"dry", `id`:7, `name`:"toe bone", `side`:"right", `subname`:2})
create (_7:`LEG`:`BONES` {`condition`:"dry", `id`:8, `name`:"toe bone", `side`:"right", `subname`:3})
create (_8:`LEG`:`BONES` {`condition`:"dry", `id`:9, `name`:"toe bone", `side`:"right", `subname`:4})
rvanbruggen / Querying Dem Bones
Last active Aug 29, 2015
Querying Dem Bones
View Querying Dem Bones
//DEM BONES queries
// show dem bones
match (n:BONES) return n;
//condition of the bones
match (n:BONES) return distinct n.condition
//where is the lord?
match (n {name:"Lord"}) return n
View dembonesgraphgist.adoc
rvanbruggen / Graph Local queries v2.cql
Last active Aug 29, 2015
Graph Local queries v2.cql
View Graph Local queries v2.cql
//the small dataset
create (_0:`OBSERVATION_LOCATION` {`latitude`:50.737160, `location_id`:1378, `longitude`:-3.405790, `name`:"EXETER AIRPORT", `postcode`:"EX5 2"}),
(_1:`OBSERVATION_LOCATION` {`latitude`:50.736540, `location_id`:57263, `longitude`:-3.532200, `name`:"EXETER UNIVERSITY", `postcode`:"EX4 4"}),
(_2:`OBSERVATION_LOCATION` {`latitude`:58.453700, `location_id`:32, `longitude`:-3.089960, `name`:"WICK AIRPORT", `postcode`:"KW1 4"}),
(_3:`OBSERVATION_LOCATION` {`latitude`:58.287710, `location_id`:44, `longitude`:-4.442370, `name`:"ALTNAHARRA NO 2", `postcode`:"IV27 4"}),
(_4:`OBSERVATION_LOCATION` {`latitude`:57.612760, `location_id`:66, `longitude`:-5.306250, `name`:"KINLOCHEWE", `postcode`:"IV22 2"}),
(_5:`OBSERVATION_LOCATION` {`latitude`:56.866560, `location_id`:105, `longitude`:-4.707970, `name`:"TULLOCH BRIDGE", `postcode`:"PH31 4"}),
(_6:`OBSERVATION_LOCATION` {`latitude`:57.711260, `location_id`:137, `longitude`:-3.323350, `name`:"LOSSIEMOUTH", `postcode`:"IV31 6"}),
rvanbruggen / loadingthetour.cql
Created Jul 6, 2014
The 2014 Tour de France
View loadingthetour.cql
create (_0:`Race` {`distance`:"3663.5", `edition`:"101", `from`:"05/07/2014", `id`:1, `name`:"TOUR DE FRANCE", `number_of_stages`:"21", `to`:"27/07/2014", `website`:""})
create (_1:`Team` {`country`:"GBR", `id`:1, `name`:"TEAM SKY", `sportingDirectors`:"PORTAL Nicolas, KNAVEN Servais"})
create (_2:`Rider` {`country`:"GBR", `name`:"FROOME Christopher"})
create (_3:`Rider` {`country`:"AUT", `name`:"EISEL Bernhard"})
create (_4:`Rider` {`country`:"BLR", `name`:"KIRYIENKA Vasili"})
create (_5:`Rider` {`country`:"ESP", `name`:"LOPEZ GARCIA David"})
create (_6:`Rider` {`country`:"ESP", `name`:"NIEVE ITURRALDE Mikel"})
create (_7:`Rider` {`country`:"USA", `name`:"PATE Danny"})
create (_8:`Rider` {`country`:"AUS", `name`:"PORTE Richie"})
View loadwargraph.cql
//loading countries
load csv with headers from ""
as countries
fieldterminator ','
merge (country:Country {short: countries.Short, cowcode: countries.COWcode, name: countries.Name});
//load some more detailed country data
load csv with headers from ""
as countries
fieldterminator ','
View create waterloograph.cql
//create song
create (n:Song {name:'Waterloo'});
// create songparts
match (s:Song {name:'Waterloo'}) create (s)-[:STARTS_WITH]->(sp:SongPart {name:'SongPart1', type:'Verse'});
match (sp1:SongPart {name:'SongPart1'}) create (sp1)-[:PRECEDES]->(sp2:SongPart {name:'SongPart2', type:'Chorus'});
match (sp2:SongPart {name:'SongPart2'}) create (sp2)-[:PRECEDES]->(sp3:SongPart {name:'SongPart3', type:'Verse'});
match (sp3:SongPart {name:'SongPart3'}) create (sp3)-[:PRECEDES]->(sp4:SongPart {name:'SongPart4', type:'Chorus'});
match (sp4:SongPart {name:'SongPart4'}) create (sp4)-[:PRECEDES]->(sp5:SongPart {name:'SongPart5', type:'Bridge'});
match (sp5:SongPart {name:'SongPart5'}) create (sp5)-[:PRECEDES]->(sp6:SongPart {name:'SongPart6', type:'Chorus'});
View Middle East GraphGist.adoc

Friend-or-Foe Relations in the Middle East

Yesterday night, I stumbled upon yet another interesting graph:


The "interactive" version of this image can be found on on this website: they basically try to interactively visualise the interplay of parties that are intervening in the many conflicts currently happening in the Middle East. It’s very, very well done.

So I did a little digging, and found that the original data is in a google doc that you can find over here. Look at the second tab: it’s basically an adjacency matrix of relationships between parties. In other words: a graph.