A "Mood" is a group of "Genre". I can get easily all "Movies" associated to a "Mood" but I strugle to do the opposite: how can I get the "Mood" of a "Movie"?
Note that the complexity lies in the fact that a Movie is associated to a Mood if all the Genre of the Mood are link to the Movie.
In the example image my Movie belongs to the "Fiction & Romance" Mood but not to the "Action & Thriller" Mood.
Thanks for your help!
If I understand your requirement, you would like to identify a movie's moods. By definition, a movie has a specific mood if the movie is connected to all of the genres that connect to the mood. If this is correct statement, then the following query will identify which potential moods a movie can have is a mood or not.
Basically, the query does the following:
- Finds the movie of interest
- Finds all moods connected to the movie
- Finds all genres connected to the movie
- Finds all genres connected to each mood
- Checks if all the genres of the mood are within the set of the movie genres. if true, the movie has that mood. if not, the movie does not.
with distinct n as moods, m
with m, moods
with m, collect(gm) as genreOfMovie, moods
return genreOfMovie, collect(gn) as genreOfMood
return m.title as movie, moods.name as mood, all(i in genreOfMood where i in genreOfMovie) as inMood
Here is my test data and results. You will need to alter the relationship directions if my test data has different directions than your data model.
Thanks @glilienfield for the query and clear explanations, it worked like a charm!
Note for other people information.
*I ask on discord to @hakan.lofqvist1 whether it can be relevant to create a relation between Mood and Movie : *
"Yes and no. Yes = if you run gds algo or some other heavy query to figure out the best mood. No = if it can be a fast local query."
=> In our use case it's preferable to use a cypher query for now.
Also he mentionned as an interesting solution to organize your Moods into a hierarchy (for instance by running similarity overlap on a (:Movie)-->(:Genre) graph). Because then you can get Movie -> Fiction & Romance <-[:CHILD_TO]- Romance.
Thank you both