cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Set property for relationships in Neo4j

Note: I have asked this question in stackoverflow as well (https://stackoverflow.com/questions/60636486/set-property-for-relationships-in-neo4j). I am new to Neo4j and working on the movielens dataset. The graph that I am trying to create is as follows: (User{userID,Gender,Age,Occupation})-[WATCHED{Rating}]->(Movie{Title,Genres}), where userID,Gender,Age,Occupation are properties of user, Rating is a property of WATCHED relationship and Title,Genres are properties of Movie.

My data looks like this:

UserID;Gender;Age;Occupation;MovieID;Ratings;Title;Genres
4;M;45;7;3468,1210,2951,1214,1036,260,2028,480,1196;5,3,4,4,4,5,5,4,2;Star Wars- Episode IV - A New Hope (1977),Jurassic Park (1993),Die Hard (1988),E.T. the Extra-Terrestrial (1982),Star Wars- Episode V - The Empire Strikes Back (1980),Raiders of the Lost Ark (1981),Good The Bad and The Ugly The (1966),Star Wars- Episode VI - Return of the Jedi (1983),Alien (1979);Action|Adventure|Fantasy|Sci-Fi,Action|Adventure|Sci-Fi,Action|Thriller,Childrens|Drama|Fantasy

The query I used to create the user and movie nodes is:

LOAD CSV WITH HEADERS FROM 'file:///user_movie_info_user-rating.csv' AS line FIELDTERMINATOR ';'
WITH line,SPLIT(line.MovieID, ",") AS Movie,SPLIT(line.Title, ",") AS Title,SPLIT(line.Genres, ",") AS Genres
MERGE (u:User { uID:TOINTEGER(line.UserID),gender:line.Gender,age: TOINTEGER(line.Age),occupation:TOINTEGER(line.Occupation)})
WITH Movie,Title,Genres
UNWIND RANGE(0, SIZE(Movie)-1) as j
MERGE (m:Movie {MovieID:TOINTEGER(Movie[j]),Title:Title[j],Genre:Genres[j]})

The query to create relationship between nodes is:

MATCH (m:Movie),(u:User) WHERE u.uID=1 AND m.MovieID in [3468,1210,2951,1214,1036,260,2028,480,1196] CREATE (u)-[s:WATCHED]->(m) RETURN type(s)

However, I am not sure how to add the ratings to the WATCHED relationship. I tried this

MATCH p=(u:User)-[r:WATCHED]->(m:Movie) WHERE u.uID=1 AND m.MovieID=1193 SET r.Rating=[5],

but this needs to be run for each and every movie. Is there a better way?

0 REPLIES 0