Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-11-2022 05:54 AM
Hi Graphistas,
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!
01-11-2022 04:44 PM
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:
match(m:Movie{title:'Batman'})
match(m)-->(g:Genre)-->(n:Mood)
with distinct n as moods, m
call {
with m, moods
match(m)-[:IN_GENRE]->(gm)
with m, collect(gm) as genreOfMovie, moods
match(gn)-[:IN_MOOD]->(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.
01-12-2022 06:29 AM
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
All the sessions of the conference are now available online