Created
November 2, 2018 15:51
-
-
Save infinite-Joy/a7889d047ce7e8f3ed1e50297fe16c7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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