Skip to content

Instantly share code, notes, and snippets.

View vladbatushkov's full-sized avatar
🥥
Sabai sabai

Vlad Batushkov vladbatushkov

🥥
Sabai sabai
View GitHub Profile
@vladbatushkov
vladbatushkov / omgc-may-11-5.cypher
Created May 11, 2019 16:57
Parse followers of band by genre.
MATCH (b:Band)-[:OF]->(g:Genre { name: "Rock" })
CALL apoc.load.html("https://last.fm/music/" + replace(b.name, " ", "+") + "/+listeners", { data: "h4.user-list-name a" }) YIELD value
UNWIND value.data as n
MERGE (p:Person { name: n.text })
MERGE (p)-[:LIKES]->(b)
@vladbatushkov
vladbatushkov / omgc-may-11-6.cypher
Created May 11, 2019 16:59
Reccomend person to listen bands, that other persons with similar preferences like.
MATCH (vb:Person { name: "vlad batushkov" })-[:LIKES]->(cross_band:Band)<-[:LIKES]-(p:Person)-[:LIKES]->(other_band:Band)
WHERE NOT (vb)-[:LIKES]->(other_band)
WITH other_band.name as name, count(p) as followers_num
RETURN name, followers_num
ORDER BY followers_num DESC
LIMIT 10
MERGE (red:Color { name: "Red" })
MERGE (white:Color { name: "White" })
MERGE (blue:Color { name: "Blue" })
MERGE (green:Color { name: "Green" })
MERGE (yellow:Color { name: "Yellow" })
MERGE (black:Color { name: "Black" })
MERGE (f1:Flag { name: "Belarus" })
MERGE (f1)-[:CONTAINS { weight: 60 }]->(red)
MERGE (f1)-[:CONTAINS { weight: 30 }]->(green)
MERGE (f1)-[:CONTAINS { weight: 10 }]->(white)
MATCH (:Flag)-[c1:CONTAINS]->(:Color)
WITH sum(c1.weight) as total
MATCH (:Flag)-[c2:CONTAINS]->(cl:Color)
WITH cl.name as colorName, sum(c2.weight) as colorUsed, total
RETURN colorName, colorUsed * 100 / total as percentage
ORDER BY percentage DESC
LIMIT 10
MATCH (f:Flag), (cl:Color)
OPTIONAL MATCH (f)-[c:CONTAINS]->(cl)
WITH { item:id(f), weights: collect(coalesce(c.weight, 0)) } as flagData
WITH collect(flagData) as data
CALL algo.similarity.cosine.stream(data)
YIELD item1, item2, count1, count2, similarity
RETURN algo.asNode(item1).name AS flag_of, algo.asNode(item2).name AS to_flag_fo, similarity
ORDER BY similarity DESC
LIMIT 15
@vladbatushkov
vladbatushkov / omgc-may-13-1.cypher
Last active May 14, 2019 13:17
All winners of Formula 1.
UNWIND range(1950, 2018) as year
WITH "https://www.formula1.com/en/results.html/" + year + "/races.html" as url, year
CALL apoc.load.html(url, { place: "table.resultsarchive-table tbody tr td:eq(1)", pilot: "table.resultsarchive-table tbody tr td:eq(3)" }) YIELD value
WITH collect(value) as data, year
WITH { pilots: data[0].pilot, places: data[1].place } as root, year
WITH [ x IN range(0, length(root.pilots) - 1) | { pilot: root.pilots[x].text, place: root.places[x].text }] as result, year
UNWIND result as item
MERGE (y:Year { value: year })
MERGE (p:Pilot { name: item.pilot })
MERGE (c:Country { name: item.place })
@vladbatushkov
vladbatushkov / omgc-may-13-2.cypher
Last active May 14, 2019 13:25
Best of the best in Formula 1.
MATCH (w:Winner)
RETURN w.pilot as pilot, count(w.pilot) as wins
ORDER BY wins DESC
LIMIT 10
@vladbatushkov
vladbatushkov / omgc-may-13-3.cypher
Last active May 14, 2019 13:26
Best at the race in Formula 1.
MATCH (w:Winner)
RETURN w.pilot as pilot, w.country as race, count(w.pilot) as wins
ORDER BY wins DESC
LIMIT 10
@vladbatushkov
vladbatushkov / omgc-may-16-1.cypher
Created May 16, 2019 17:26
Parse Oscar movies.
WITH "https://www.hollywoodreporter.com/lists/oscar-nominations-2019-complete-list-nominees-1172407/item/best-director-1172474" as url
CALL apoc.load.html(url, { movie: "ul.list--unordered__items li div.list-item__body a" }) YIELD value
WITH collect(value) as data
WITH { movies: data[0].movie } as root
WITH [x IN range(0, length(root.movies) - 1) | { title: root.movies[x].text, url: root.movies[x].attributes.href }] as result
WITH filter(x IN result WHERE x.title <> "" AND apoc.text.indexOf(x.url, "/review/") > -1) as titled
UNWIND titled as item
MERGE (m:Movie { title: item.title })
ON CREATE SET m.url = apoc.text.replace(item.url, "edit.", "www.")
ON MATCH SET m.url = apoc.text.replace(item.url, "edit.", "www.")
@vladbatushkov
vladbatushkov / omgc-may-16-2.cypher
Created May 16, 2019 17:34
Set keywords from movie review.
MATCH (m:Movie)
CALL apoc.load.html(m.url, { reviews: "div.article__body p" }) YIELD value
WITH split(value.reviews[0].text + " " + value.reviews[1].text, " ") as keywords, m
WITH [x IN keywords | apoc.text.replace(x, "[\\.\\,\\(\\)\\']", "")] as keywords, m
SET m.keywords = filter(x IN keywords WHERE size(x) > 4)