I wanted to make a variant of the exercise and verify automatically which are the unique genres . This is my solution:
call{
MATCH (n:Movie)
WHERE n.imdbRating IS NOT NULL AND n.poster IS NOT NULL
WITH n {
.title,
.imdbRating,
actors: [ (n)<-[:ACTED_IN]-(p) | p { tmdbId:p.imdbId, .name } ],
genres: [ (n)-[:IN_GENRE]->(g) | g {.name}]
}
ORDER BY n.imdbRating DESC
LIMIT 4
RETURN collect(n) as listOfFilms
}
call{
with listOfFilms
unwind listOfFilms as x
with uniquegen = [genx{.name} in x.genres where
unwind listOfFilms as y
isEmpty(\[geny{.name} in y.genres where x<>y and geny.name\=geny.name \]
)
]
return uniquegen
}
return uniquegen
The second call doesn't work since I get an error for the presence of "where " after x.genres in the definition of the list. There I wanted to use a list comprehension to define a list of genres that are unique: that genre is present in only one movie in the list got from the first call. Why I get that error ?
The problem is in the second call:
With unwind I get x as iterator for listOfFilm then I build the list uniqueGen doing so: I add genx{.name} in the list (genx is an element of list x) only if there isn't an other element geny with genx = geny and geny got from list y with y iterator on listOfFilm, as previously, I verify also x<>y otherwise the film could be the same.