Match movie entities that are in more than one role or share similar roles


#1

I have a movie entity that is in a tagging relationship between itself and a genre:

tagging sub relationship,
        relates tagged, 
        relates tagger;

the tagged role is the movie and then the tagger role is the genre. I did this because I was trying to achieve having multiple genres related to a movie.

Now I am trying to write a rule that can match movie entities with more than one genres or who share more than one genre. My reason behind this is that if two movies share more than one genre then they are similar and vice versa. So for this is the rule I have written

movie_is_similar sub rule
when {
    (tagged: $movie_a, tagger: $genre) isa tagging;
    (tagged: $movie_b, tagger: $genre) isa tagging;
},
then {
    (tagged: $movie_a, similar_to: $movie_b) isa similar_movie;
};

However this rule only matches for one genre, meaning it only matches anime who share one genre.

your help is greatly appreciated.


#2

Hey,

So if you define a rule like:

shared-tagging sub rule
when {
(tagged: $movie_a, tagger: $genre) isa tagging;
(tagged: $movie_b, tagger: $genre) isa tagging;
},
then {
(tagged: $movie_a, tagged: $movie_b, tagger: $genre) isa shared-tagging;
};

Then you can query, for example, for movies sharing at least 2 genres by doing;

match 
(tagged: $movie_a, tagged: $movie_b, tagger: $genre) isa shared-tagging;
(tagged: $movie_a, tagged: $movie_b, tagger: $genre2) isa shared-tagging;
$genre != $genre2;
get;

Hope that helps.