How to find all adequate terms in a prolog database?

I have a database containing the following terms:

movie(american_beauty, 1999).
director(american_beauty, sam_mendes).
actor(american_beauty, kevin_spacey, lester_burnham).
actress(american_beauty, annette_bening, carolyn_burnham).
actress(american_beauty, thora_birch, jane_burnham).
movie(anna, 1987).
director(anna, yurek_bogayevicz).
actress(anna, sally_kirkland, anna).
actor(anna, robert_fields, daniel).
actress(anna, paulina_porizkova, krystyna).
movie(barton_fink, 1991).
director(barton_fink, ethan_coen).
director(barton_fink, joel_coen).
actor(barton_fink, john_turturro, barton_fink).
...

How to find all actors and actresses who play in one movie only?

How can I iterate through all the database or collect all data with recursion?

I can tell if an actor or actress plays in a given movie with:

plays(Actor,Movie):-
    actor(Movie,Actor,_).

plays(Actor,Movie):-
    actress(Movie,Actor,_).

I wold like to write a function such as:

how_many_movies(actor,number):-

and iterate through the actors and actresses, find how many movies do they play

in and print only those who have one movie. How can I do it? Or is it a wrong direction?



Read more here: https://stackoverflow.com/questions/64416661/how-to-find-all-adequate-terms-in-a-prolog-database

Content Attribution

This content was originally published by ann at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: