Skip to content

Instantly share code, notes, and snippets.

View freeeve's full-sized avatar

Eve Freeman freeeve

  • Fairfax, VA
View GitHub Profile
beer paraphraser
feat enactment swive hid muck
confectionery
byssus genuine
astrictive Australia
quintuple Ching huff
back matter traumatism
subj calorifacient mire
package main
import (
"bufio"
"fmt"
"math/rand"
"os"
"strings"
"time"
CREATE (e:Erdos);
LOAD CSV FROM "http://www4.skeweredrook.com/Erdos-remix.csv" AS coll
WITH coll[0] AS first, toInt(coll[1]) AS year, toInt(coll[2]) as count, coll[3..] AS conns
MATCH (e:Erdos)
MERGE (p:Person {name:first}) ON CREATE SET p.year = year, p.count = coalesce(count, 1)
MERGE (p)-[:COLLABORATED_WITH]-(e)
WITH p,conns
UNWIND conns as cName
MERGE (c:Person {name:cName})
@freeeve
freeeve / gist:830e40cb33c37472960d
Created October 10, 2014 16:02
creates a graph of erdos connections up to level 2
LOAD CSV FROM "http://www4.skeweredrook.com/Erdos-remix.csv" AS coll
WITH coll[0] AS first, toInt(coll[1]) AS year, toInt(coll[2]) as count, coll[3..] AS conns
MERGE (e:Erdos)
MERGE (p:Person {name:first}) ON CREATE SET p.year = year, p.count = coalesce(count, 1)
MERGE (p)-[:COLLABORATED_WITH]-(e)
WITH p,conns
UNWIND conns as cName
MERGE (c:Person {name:cName})
MERGE (c)-[:COLLABORATED_WITH]-(p);
@freeeve
freeeve / loadMovies.cyp
Last active August 29, 2015 14:07
load movie CSV
LOAD CSV WITH HEADERS FROM 'http://www4.skeweredrook.com/movies.csv' as record
WITH toInt(record.movieId) as movieId, record.title as title, toFloat(record.voteAverage) as avgVote, toInt(record.releaseYear) as releaseYear,
record.tagline as tagline, split(record.genres, ":") as genres, toInt(record.personId) as personId, record.name as personName,
toInt(record.birthYear) as birthYear, toInt(record.deathYear) as deathYear, split(record.characters, ":") as roles,
CASE WHEN record.personType = "ACTOR" THEN [1] ELSE [] END as actor, CASE WHEN record.personType = "DIRECTOR" THEN [1] ELSE [] END as director
MERGE (movie:Movie {id:movieId})
ON CREATE SET movie.title = title, movie.avgVote = avgVote, movie.releaseYear = releaseYear, movie.tagline = tagline, movie.genres = genres
FOREACH(x in actor | MERGE(person:Person {id:personId})
ON CREATE SET person.name = personName, person.born = birthYear, person.died = case when deathYear > 0 then deathYear else null end
MERGE (person)-[:ACTED_IN {roles:roles}]->(movie))
LOAD CSV WITH HEADERS FROM 'http://www4.skeweredrook.com/movies.csv' as record
WITH toInt(record.movieId) as movieId, toFloat(record.voteAvg) as avgVote
MERGE (movie:Movie {id:movieId})
ON MATCH SET movie.avgVote = avgVote
MATCH (a:Person)-[:ACTED_IN]->(m)-[:IS_GENRE]->(g)<-[:IS_GENRE]-()<-[:DIRECTED]-(d:Person)
WHERE a.name = "Keanu Reeves"
AND NOT (a)-[:ACTED_IN]->()<-[:DIRECTED]-(d)
AND NOT has(d.died)
WITH count(distinct g) as intersecting, a,d
MATCH (a)-[:ACTED_IN]->(m)-[:IS_GENRE]->(g)
WITH intersecting, collect(g) as keanuGenres,a,d
MATCH (d)-[:DIRECTED]->(m)-[:IS_GENRE]->(g)
WITH intersecting, keanuGenres, collect(g) as directorGenres,a,d
WITH intersecting, keanuGenres + directorGenres as unionGenres,a,d
MATCH (a:Person)-[:ACTED_IN]->(m)-[:IS_GENRE]->(g)<-[:IS_GENRE]-()<-[:DIRECTED]-(d:Person)
WHERE a.name = "Keanu Reeves"
AND NOT (a)-[:ACTED_IN]->()<-[:DIRECTED]-(d)
AND NOT has(d.died)
WITH count(distinct g) as intersecting, a,d
MATCH (a)-[:ACTED_IN]->(m)-[:IS_GENRE]->(g)
WITH intersecting, collect(distinct g) as keanuGenres,a,d
MATCH (d)-[:DIRECTED]->(m)-[:IS_GENRE]->(g)
WITH intersecting, keanuGenres, collect(distinct g) as directorGenres,a,d
RETURN toFloat(intersecting) / (length(keanuGenres) + length([x in directorGenres where not x in keanuGenres])) as score, a.name, d.name
with ['a','b','c','d','e','f','g','h'] as coll
return reduce(acc="", x in range(1,8)| acc + coll[toInt(rand()*length(coll))])
MATCH (a)-[:ACTED_IN]->(m)<-[:DIRECTED]-(d)
WITH a.name as actor, d.name as director, collect(m.title) as movies, count(1) as movieCount
UNWIND movies as movie
RETURN actor, director, movie, movieCount
ORDER BY movieCount desc;