This gist is a complement to blogpost that I wrote, and the presentation that I did at the London GraphPub about Graph Playlists and the Ultimate Dem Bones Demo. Let’s see if we can reproduce that over here.
Let’s play some music:
or if you don’t use Spotify, use this one:
First we have to load the data into the graph. This was a bit of work - but not difficult at all:
//create them bones
create (_0:`LEG`:`BONES` {`condition`:"dry", `id`:1, `name`:"toe bone", `side`:"left", `subname`:1}),
(_1:`LEG`:`BONES` {`condition`:"dry", `id`:2, `name`:"toe bone", `side`:"left", `subname`:2}),
(_2:`LEG`:`BONES` {`condition`:"dry", `id`:3, `name`:"toe bone", `side`:"left", `subname`:3}),
(_3:`LEG`:`BONES` {`condition`:"dry", `id`:4, `name`:"toe bone", `side`:"left", `subname`:4}),
(_4:`LEG`:`BONES` {`condition`:"dry", `id`:5, `name`:"toe bone", `side`:"left", `subname`:5}),
(_5:`LEG`:`BONES` {`condition`:"dry", `id`:6, `name`:"toe bone", `side`:"right", `subname`:1}),
(_6:`LEG`:`BONES` {`condition`:"dry", `id`:7, `name`:"toe bone", `side`:"right", `subname`:2}),
(_7:`LEG`:`BONES` {`condition`:"dry", `id`:8, `name`:"toe bone", `side`:"right", `subname`:3}),
(_8:`LEG`:`BONES` {`condition`:"dry", `id`:9, `name`:"toe bone", `side`:"right", `subname`:4}),
(_9:`LEG`:`BONES` {`condition`:"dry", `id`:10, `name`:"toe bone", `side`:"right", `subname`:5}),
(_10:`LEG`:`BONES` {`condition`:"dry", `id`:11, `name`:"foot bone", `side`:"left"}),
(_11:`LEG`:`BONES` {`condition`:"dry", `id`:12, `name`:"foot bone", `side`:"right"}),
(_12:`LEG`:`BONES` {`condition`:"dry", `id`:13, `name`:"shin bone", `side`:"left"}),
(_13:`LEG`:`BONES` {`condition`:"dry", `id`:14, `name`:"shin bone", `side`:"right"}),
(_14:`LEG`:`BONES` {`condition`:"dry", `id`:15, `name`:"knee bone", `side`:"left"}),
(_15:`LEG`:`BONES` {`condition`:"dry", `id`:16, `name`:"knee bone", `side`:"right"}),
(_16:`LEG`:`BONES` {`condition`:"dry", `id`:17, `name`:"thigh bone", `side`:"left"}),
(_17:`LEG`:`BONES` {`condition`:"dry", `id`:18, `name`:"thigh bone", `side`:"right"}),
(_18:`LEG`:`BONES` {`condition`:"dry", `id`:19, `name`:"hip bone"}),
(_19:`THORAX`:`BONES` {`condition`:"dry", `id`:20, `name`:"back bone"}),
(_20:`THORAX`:`BONES` {`condition`:"dry", `id`:21, `name`:"shoulder bone", `side`:"left"}),
(_21:`THORAX`:`BONES` {`condition`:"dry", `id`:22, `name`:"shoulder bone", `side`:"right"}),
(_22:`HEAD`:`BONES` {`condition`:"dry", `id`:23, `name`:"neck bone"}),
(_23:`HEAD`:`BONES` {`condition`:"dry", `id`:24, `name`:"head bone"}),
(_24:`ARM`:`BONES` {`condition`:"dry", `id`:25, `name`:"arm bone", `side`:"left"}),
(_25:`ARM`:`BONES` {`condition`:"dry", `id`:26, `name`:"arm bone", `side`:"right"}),
(_26:`ARM`:`BONES` {`condition`:"dry", `id`:27, `name`:"hand bone", `side`:"left"}),
(_27:`ARM`:`BONES` {`condition`:"dry", `id`:28, `name`:"hand bone", `side`:"right"}),
(_28:`ARM`:`BONES` {`condition`:"dry", `id`:29, `name`:"finger bone", `side`:"left", `subname`:1}),
(_29:`ARM`:`BONES` {`condition`:"dry", `id`:30, `name`:"finger bone", `side`:"left", `subname`:2}),
(_30:`ARM`:`BONES` {`condition`:"dry", `id`:31, `name`:"finger bone", `side`:"left", `subname`:3}),
(_31:`ARM`:`BONES` {`condition`:"dry", `id`:32, `name`:"finger bone", `side`:"left", `subname`:4}),
(_32:`ARM`:`BONES` {`condition`:"dry", `id`:33, `name`:"finger bone", `side`:"left", `subname`:5}),
(_33:`ARM`:`BONES` {`condition`:"dry", `id`:34, `name`:"finger bone", `side`:"right", `subname`:1}),
(_34:`ARM`:`BONES` {`condition`:"dry", `id`:35, `name`:"finger bone", `side`:"right", `subname`:2}),
(_35:`ARM`:`BONES` {`condition`:"dry", `id`:36, `name`:"finger bone", `side`:"right", `subname`:3}),
(_36:`ARM`:`BONES` {`condition`:"dry", `id`:37, `name`:"finger bone", `side`:"right", `subname`:4}),
(_37:`ARM`:`BONES` {`condition`:"dry", `id`:38, `name`:"finger bone", `side`:"right", `subname`:5}),
(_40:`FANTASY` {`name`:"Lord"}),
(_41:`FANTASY` {`name`:"Word"}),
(_81:`LEG`:`BONES` {`condition`:"dry", `name`:"ankle bone", `side`:"left"}),
(_82:`LEG`:`BONES` {`condition`:"dry", `name`:"ankle bone", `side`:"right"}),
_0-[:`CONNECTED_TO`]->_10,
_1-[:`CONNECTED_TO`]->_10,
_2-[:`CONNECTED_TO`]->_10,
_3-[:`CONNECTED_TO`]->_10,
_4-[:`CONNECTED_TO`]->_10,
_5-[:`CONNECTED_TO`]->_11,
_6-[:`CONNECTED_TO`]->_11,
_7-[:`CONNECTED_TO`]->_11,
_8-[:`CONNECTED_TO`]->_11,
_9-[:`CONNECTED_TO`]->_11,
_10-[:`CONNECTED_TO`]->_81,
_11-[:`CONNECTED_TO`]->_82,
_12-[:`CONNECTED_TO`]->_14,
_13-[:`CONNECTED_TO`]->_15,
_14-[:`CONNECTED_TO`]->_16,
_15-[:`CONNECTED_TO`]->_17,
_16-[:`CONNECTED_TO`]->_18,
_17-[:`CONNECTED_TO`]->_18,
_18-[:`CONNECTED_TO`]->_19,
_19-[:`CONNECTED_TO`]->_21,
_19-[:`CONNECTED_TO`]->_20,
_19-[:`CONNECTED_TO`]->_20,
_20-[:`CONNECTED_TO`]->_22,
_21-[:`CONNECTED_TO`]->_22,
_22-[:`CONNECTED_TO`]->_23,
_24-[:`CONNECTED_TO`]->_20,
_25-[:`CONNECTED_TO`]->_21,
_26-[:`CONNECTED_TO`]->_24,
_27-[:`CONNECTED_TO`]->_25,
_28-[:`CONNECTED_TO`]->_26,
_29-[:`CONNECTED_TO`]->_26,
_30-[:`CONNECTED_TO`]->_26,
_31-[:`CONNECTED_TO`]->_26,
_32-[:`CONNECTED_TO`]->_26,
_33-[:`CONNECTED_TO`]->_27,
_34-[:`CONNECTED_TO`]->_27,
_35-[:`CONNECTED_TO`]->_27,
_36-[:`CONNECTED_TO`]->_27,
_37-[:`CONNECTED_TO`]->_27,
_40-[:`SPEAKS`]->_41,
_41-[:`IS_AT`]->_23,
_81-[:`CONNECTED_TO`]->_12,
_82-[:`CONNECTED_TO`]->_13;
Let’s see what we have added. Here are the Bones:
//where are dem bones?
match (n:BONES)-[r]->() return count(n) as NrOfNodes
And their connections:
//find the connected bones - part 2?
match (n)-[r:CONNECTED_TO]->(m)
return count(r) as NrOfRels;
Then we can do some easy queries.
//where are dem bones?
match (n:BONES) return distinct n.name as DemBones
This is what it looks like:
Let’s explore some paths. Let’s look at the paths between the foot and the head! Note that you can maximize and minimize the visualisations at all time!
//find the paths between the foot bone and the head bone
match (n:BONES {name:"foot bone"}), (m:BONES {name:"head bone"}), p = AllShortestPaths (n-[*]-m) return p;
Let’s explore from the head to the fingers:
//find the paths between head bone and finger bone
match p = AllShortestPaths((n:BONES {name:"head bone"})-[*]-(m:BONES {name:"finger bone"})) return p;
And here’s the complete graph:
But hey - this isn’t over yet. Dem Bones are gonna WHAT?
//Dem Bones are gonna what?
merge (m:ACTIVITY {name:"Marching"})
with m
match (n:BONES)
merge n-[:ENGAGE_IN]->m
return n,m
Indeed! Dem gonna MARCH!
I hope this gist complements the blogpost so that you can have even MORE fun with neo4j and music.
This gist was created by Rik Van Bruggen