Skip to content

Instantly share code, notes, and snippets.

@infinite-Joy
Created November 2, 2018 15:51
Show Gist options
  • Save infinite-Joy/a7889d047ce7e8f3ed1e50297fe16c7f to your computer and use it in GitHub Desktop.
Save infinite-Joy/a7889d047ce7e8f3ed1e50297fe16c7f to your computer and use it in GitHub Desktop.
print('Create the movieid-belongsto->genres relationship')
with driver.session() as session:
with open('movies.csv') as f:
reader = csv.DictReader(f, delimiter=",")
for line in reader:
movieid = line['movieId']
genres = line['genres'].split('|')
movies = {"records": [{'movieId': movieid, 'genres': genres}]}
create_movie_genre_relationship = '''
UNWIND {records} as record
MATCH (a:MovieId) where a.movieId=record.movieId
MATCH (b:Genre) where b.name in record.genres
CREATE (a)-[:BELONGSTO]->(b)
'''
result = session.run(create_movie_genre_relationship, movies)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment