In Python,1.6. Recommend a Movie Create a function that counts how many keywords are similar in a set of movie reviews and recommend the movie with the most similar number of keywords. The solution to this task will require the use of dictionaries. The film reviews & keywords are in a file called film_reviews.txt, separated by commas. The first term is the movie name, the remaining terms are the film’s keyword tags (i.e., “amazing", “poetic", “scary", etc.). Function name: similar_movie() Parameters/arguments: name of a movie Returns: a list of movies similar to the movie passed as an argument
film_reviews.txt
7 Days in Entebbe,fun,foreign,sad,boring,slow,romance
12 Strong,war,violence,foreign,sad,action,romance,bloody
A Fantastic Woman,fun,foreign,sad,romance
A Wrinkle in Time,book,witty,historical,boring,slow,romance
Acts of Violence,war,violence,historical,action
Annihilation,fun,war,violence,gore,action
Armed,foreign,sad,war,violence,cgi,fancy,action,bloody
Black '47,fun,clever,witty,boring,slow,action,bloody
Black Panther,war,violence,comicbook,expensive,action,bloody
# this function will return the movie with maximum number of matching reviews to the movies in the file and function can be completed without dictionaries.
# The function similar_movie() should be as follows----------------:>
(Assuming film_reviews is in the same directory as of the python file)
===========================================================================================
def similar_movie(m):
movies = list()
reviews = list()
film = open("read.txt")
a = film.readlines()
for line in a:
line = line.strip()
b = line.split(",")
movies.append(b[0])
reviews.append(b[1:])
print(movies)
print(reviews)
index = movies.index(m)
max_match = list([])
final = list()
z = 0
for i in reviews:
count = 0
if z is index:
max_match.append(0)
z += 1
continue
for j in reviews[index]:
if j in i:
count += 1
max_match.append(count)
z += 1
print(max_match)
match_value = max(max_match)
y = 0
for i in max_match:
if i is match_value:
final.append(y)
y += 1
final_movies = list()
for i in final:
final_movies.append(movies[i])
return final_movies
=======================================================================================
In Python,1.6. Recommend a Movie Create a function that counts how many keywords are similar in...