serhii.net

In the middle of the desert you can say anything you want

WHY IS THIS HERE DANGER

24 Jan 2023

DS Neo4j

Tasks:

  • show graph schema: ![assets/2023-01-24-144129_916x532_scrot.png]({{ site.assets_location }}/d3418f21686134a16755203c927975e0c5e3e17736943d296cc72763ed4fef9c.png)
  • 10 artists: ![assets/2023-01-24-144430_905x590_scrot.png]({{ site.assets_location }}/09f2292f432b81a8b0d64285f366721518afa800bf55974e9a60456ad3a11aa6.png)
  • artists of pop>=95 and their songs: ![assets/2023-01-24-150118_903x542_scrot.png]({{ site.assets_location }}/21cefce9fcb5a8ae5a2023ae62665ae571821c47d44f4624af7865a80edda00d.png)
    MATCH (t:Track) - [:FROM_ARTIST] -> (a:Artist) WHERE (a.popularity >=95) RETURN t,a
    
  • songs with pop.>95: ![assets/2023-01-24-150437_916x415_scrot.png]({{ site.assets_location }}/83a0ee47b3e137533d58ccf472369c711a57007cdda48544075baf86de627f73.png)
  • ./., odered by popularity asc: ![assets/2023-01-24-150607_932x438_scrot.png]({{ site.assets_location }}/af6867bc32b70997b11e4d3804048063d6b01fa7d7d695bb21ff6fad8d66cc0b.png)
    MATCH (t:Track) WHERE (t.popularity>95) RETURN t.name,t.popularity as popularity ORDER BY popularity asc
    
  • artists with 80<pop<85 desc: MATCH (a:Artist) WHERE (a.popularity>80) AND (a.popularity)<85 RETURN a.name,a.popularity ORDER BY a.popularity DESC
  • count artists: MATCH (t:Track) WHERE (t.popularity>90) RETURN count(t) as number: ![assets/2023-01-24-151026_909x169_scrot.png]({{ site.assets_location }}/28253f4ac62e89bf477963f7e39fdd7c2b1a6ce65b61297fa9e600da4f4b2bcc.png)
  • show as a graph songs in “mint”: MATCH (t:Track)-[:IN_PLAYLIST]->(n:Playlist {name:'mint'}) RETURN t
    1. Which artist contributed to Migos’ song “Walk it talk it” (drake): MATCH (n:Track {name:"Walk It Talk It"})-[:FROM_ARTIST]->(a:Artist) WHERE a.name <> "Migos" RETURN a
    1. nodes reachable in 1-2 hops through FOLLOWS from Karolina: ![assets/2023-01-24-152309_848x549_scrot.png]({{ site.assets_location }}/91c2d4cf65fa6620a054c9525254da6ae1c06401dfe6211bdd992084d5d4d62c.png) MATCH (u:User {name:"Karolina"}) -[:FOLLOWS*1..2]-(uu) RETURN u,uu (undirected edges)

Advanced:

  • Return all artists Daniel likes: MATCH (u:User {name:"Daniel"})-[:LIKES]->(t:Track)-[:FROM_ARTIST]->(a:Artist) RETURN DISTINCT a (18) ![assets/2023-01-24-153203_916x599_scrot.png]({{ site.assets_location }}/75fefdc99711e0a85bab67a677f1cb559243a024c50048a53ab6db391e79c3ff.png)
  • 12: top-5 artists by num of songs + average popularity of songs of artists, decr order: MATCH (s:Track)-[:FROM_ARTIST]->(a:Artist) RETURN a,count(s) as num,avg(s.popularity) as avgpop ORDER BY num DESC LIMIT 5:![assets/2023-01-24-153546_899x587_scrot.png]({{ site.assets_location }}/b306178156203982b2342511a49f60ed9af75039f893fc457ddc85430a36e1ee.png)
  • 13: songs of Ed Sheeran and someone else: MATCH (aa:Artist)<-[:FROM_ARTIST]-(s:Track)-[:FROM_ARTIST]->(a:Artist {name:"Ed Sheeran"}) WHERE a<>aa RETURN DISTINCT s.name,aa.name: ![assets/2023-01-24-154008_905x620_scrot.png]({{ site.assets_location }}/a4e722e8d4f9e400908e115763872d295531211046e36afb1913ad8ae91c4fd5.png)
  • 14: w/ songs of the other artists: MATCH (ss:Track)-[:FROM_ARTIST]->(aa:Artist)<-[:FROM_ARTIST]-(s:Track)-[:FROM_ARTIST]->(a:Artist {name:"Ed Sheeran"}) RETURN ss.name,aa.name,s.name ![assets/2023-01-24-154439_907x599_scrot.png]({{ site.assets_location }}/55ed0bda2825b52dcc78135ab0c06abc3a8aca4dd04afc84a94095148fb31962.png) (I removed the <> and DISTINCT part.)
  • 15: y+m when Karolina liked the most songs: MATCH (u:User {name:"Karolina"})-[l:LIKES]->(s:Track) RETURN l.since.month as month, l.since.year as year, count(l) as liked ORDER BY liked DESC:![assets/2023-01-24-155110_926x634_scrot.png]({{ site.assets_location }}/92c96e3f9893ea1e9462b732ffbf2080aacf77d4b24961fe1c77ae3cd34d22c8.png)
  • 16: artist that appears the most often in playlists with songs from before 2000: MATCH (a:Artist)<-[:FROM_ARTIST]-(s:Track)-[:IN_PLAYLIST]->(p:Playlist) WHERE s.release_date.year<2000 RETURN a.name,count(a.name) as how_often ORDER BY how_often DESC![assets/2023-01-24-155957_919x627_scrot.png]({{ site.assets_location }}/3db86de32a14478d7e3d99a834a135b41916b757ff44177dcdd8d885c703d533.png)
Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus