From 5a638561ef1d521ec02d74b72a79fb7271b6c79d Mon Sep 17 00:00:00 2001 From: jamster3000 Date: Tue, 14 Nov 2023 10:30:32 +0000 Subject: [PATCH] film knowledge --- Joan.py | 13 ++- data/ET.csv | 3 +- data/last time used.txt | 2 +- data/log.txt | 34 +++++++ data/movie data.json | 26 +++++ data/responses.csv | 2 +- data/user data.csv | 2 +- interactions.py | 216 ++++++++++++++++++++++++++-------------- 8 files changed, 219 insertions(+), 79 deletions(-) diff --git a/Joan.py b/Joan.py index 14c9905..f169081 100644 --- a/Joan.py +++ b/Joan.py @@ -580,7 +580,7 @@ def process_input(user_input, vectorizer, classifier, er_vectorizer, er_classifi elif entity == 'year': tell_year() elif entity == 'movie release': - user_input = user_input.lower().lstrip().replace('when', '').replace('did', '').replace('release', '') + user_input = user_input.lower().lstrip().replace('when', '').replace('did', '').replace('release', '').replace('released', '').replace('was', '') movie.collect_data(user_input, movie.release) elif entity == 'weather monday': weather_day('monday') @@ -613,9 +613,16 @@ def process_input(user_input, vectorizer, classifier, er_vectorizer, er_classifi elif entity == 'movie writer': user_input = user_input.replace('who', '').replace('wrote', '').replace('is', '').replace('writer', '').replace('for', '') movie.collect_data(user_input, movie.writer) - elif entity == 'movie actor':#TODO: Not working. - user_input = user_input.replace('actors', '').replace('acted', '').replace('for', '').replace('who', '').replace('in', '').replace('actor', '') + elif entity == 'movie actor': + user_input = user_input.replace('actors', '').replace('acted', '').replace('for', '').replace('who', '').replace('in', '').replace('actor', '').replace('is', '').replace('the', '') movie.collect_data(user_input, movie.actor) + elif entity == 'movie plot': + user_input = user_input.replace('what', '').replace('is', '').replace('the', '').replace('plot', '').replace('of', '').rstrip().lstrip().title() + movie.collect_data(user_input, movie.plot) + elif entity == 'languages': + pass + elif entity == 'awards': + pass else: chatbot_tools.big_guns(user_input) diff --git a/data/ET.csv b/data/ET.csv index 952e94c..67049ef 100644 --- a/data/ET.csv +++ b/data/ET.csv @@ -277,4 +277,5 @@ who directed ,movie director who wrote ,movie writer who is the writer for ,movie writer who acted in ,movie actor -actor for ,movie actor \ No newline at end of file +actor for ,movie actor +what is the plot of ,movie plot diff --git a/data/last time used.txt b/data/last time used.txt index 6a0ec10..6e870f2 100644 --- a/data/last time used.txt +++ b/data/last time used.txt @@ -1 +1 @@ -22/10/2023 \ No newline at end of file +14/11/2023 \ No newline at end of file diff --git a/data/log.txt b/data/log.txt index d35482d..2097770 100644 --- a/data/log.txt +++ b/data/log.txt @@ -176,3 +176,37 @@ 2023-10-22 08:50:38.077978: Time taken to preprocess data: 4.043442964553833 2023-10-22 08:51:27.402788: All libraries imported. Time taken... 3.0200369358062744 2023-10-22 08:51:27.402788: Time taken to preprocess data: 1.3676633834838867 +2023-10-24 09:29:20.388704: All libraries imported. Time taken... 15.690319061279297 +2023-10-24 09:29:20.388704: Time taken to preprocess data: 1.413221836090088 +2023-10-24 16:12:19.238277: All libraries imported. Time taken... 5.728260517120361 +2023-10-24 16:12:19.238277: Time taken to preprocess data: 0.8861391544342041 +2023-11-13 13:09:29.412308: All libraries imported. Time taken... 23.60764193534851 +2023-11-13 13:09:29.412308: Time taken to preprocess data: 4.728177785873413 +2023-11-13 13:12:48.751046: All libraries imported. Time taken... 3.110445261001587 +2023-11-13 13:12:48.751046: Time taken to preprocess data: 1.3026080131530762 +2023-11-13 14:45:25.591961: All libraries imported. Time taken... 3.014857530593872 +2023-11-13 14:45:25.591961: Time taken to preprocess data: 1.3745858669281006 +2023-11-13 14:46:12.970297: All libraries imported. Time taken... 2.991736650466919 +2023-11-13 14:46:12.970297: Time taken to preprocess data: 1.283196210861206 +2023-11-13 14:47:40.253751: All libraries imported. Time taken... 2.8511130809783936 +2023-11-13 14:47:40.253751: Time taken to preprocess data: 1.460028886795044 +2023-11-13 14:48:14.648207: All libraries imported. Time taken... 2.964568614959717 +2023-11-13 14:48:14.648207: Time taken to preprocess data: 1.273550033569336 +2023-11-13 14:48:46.696941: All libraries imported. Time taken... 2.8485889434814453 +2023-11-13 14:48:46.696941: Time taken to preprocess data: 1.3245408535003662 +2023-11-13 14:49:32.768073: All libraries imported. Time taken... 2.9710135459899902 +2023-11-13 14:49:32.768073: Time taken to preprocess data: 1.29866623878479 +2023-11-13 14:50:30.467662: All libraries imported. Time taken... 3.5328078269958496 +2023-11-13 14:50:30.467662: Time taken to preprocess data: 1.3767578601837158 +2023-11-13 14:55:04.872208: All libraries imported. Time taken... 3.0198216438293457 +2023-11-13 14:55:04.872208: Time taken to preprocess data: 1.2605526447296143 +2023-11-13 14:55:45.362623: All libraries imported. Time taken... 2.873882293701172 +2023-11-13 14:55:45.362623: Time taken to preprocess data: 1.371633529663086 +2023-11-13 14:56:30.688564: All libraries imported. Time taken... 2.8922009468078613 +2023-11-13 14:56:30.688564: Time taken to preprocess data: 1.2959380149841309 +2023-11-13 14:57:22.715742: All libraries imported. Time taken... 3.7966020107269287 +2023-11-13 14:57:22.715742: Time taken to preprocess data: 1.2846026420593262 +2023-11-14 08:49:29.593592: All libraries imported. Time taken... 6.704172611236572 +2023-11-14 08:49:29.593592: Time taken to preprocess data: 0.8712358474731445 +2023-11-14 09:03:17.674251: All libraries imported. Time taken... 3.3468151092529297 +2023-11-14 09:03:17.674251: Time taken to preprocess data: 1.3548614978790283 diff --git a/data/movie data.json b/data/movie data.json index fa534a3..e8acd2b 100644 --- a/data/movie data.json +++ b/data/movie data.json @@ -11,5 +11,31 @@ "languages": "English, Turkish", "awards": "Nominated for 1 Oscar. 72 wins & 67 nominations total", "rate": "96%" + }, + "The Terminator": { + "Year": "26 Oct 1984", + "rated": "R", + "runTime": "107 min", + "genre": "Action, Sci-Fi", + "director": "James Cameron", + "writer": "James Cameron, Gale Anne Hurd, William Wisher", + "actors": "Arnold Schwarzenegger, Linda Hamilton, Michael Biehn", + "plot": "A human soldier is sent from 2029 to 1984 to stop an almost indestructible cyborg killing machine, sent from the same year, which has been programmed to execute a young woman whose unborn son is the key to humanity's future salvat...", + "languages": "English, Spanish", + "awards": "8 wins & 7 nominations", + "rate": "100%" + }, + "Terminator 2: Judgment Day": { + "Year": "03 Jul 1991", + "rated": "R", + "runTime": "137 min", + "genre": "Action, Sci-Fi", + "director": "James Cameron", + "writer": "James Cameron, William Wisher", + "actors": "Arnold Schwarzenegger, Linda Hamilton, Edward Furlong", + "plot": "A cyborg, identical to the one who failed to kill Sarah Connor, must now protect her ten year old son John from an even more advanced and powerful cyborg.", + "languages": "English, Spanish", + "awards": "Won 4 Oscars. 38 wins & 33 nominations total", + "rate": "91%" } } \ No newline at end of file diff --git a/data/responses.csv b/data/responses.csv index 1b774dc..1d1f74e 100644 --- a/data/responses.csv +++ b/data/responses.csv @@ -120,4 +120,4 @@ bot favourite,bot favourite,As a computer I do not have a favourite.,"As a smart created,created,A student called Jamie Baines created me using the programing language called python., gender,gender,"Do not mistake my gender attributes of my female name and female sounding voice, as a smart assistant I do not have a specific gender.","As a smart assistant I do not have a gender, although I am given a female voice and name, I do not have a gender to be specificed by." version,version,I am version , -user thinking,user thinking,"Youre thinking, Ill be damed if she gets this right.","Until I tell you what I’m thinking, I’m thinking exactly what you’re thinking, and exactly what you’re not thinking at the same time." +user thinking,user thinking,"Youre thinking, Ill be damed if she gets this right.","Until I tell you what I’m thinking, I’m thinking exactly what you’re thinking, and exactly what you’re not thinking at the same time." \ No newline at end of file diff --git a/data/user data.csv b/data/user data.csv index 9db0829..c823838 100644 --- a/data/user data.csv +++ b/data/user data.csv @@ -1,2 +1,2 @@ index,first name,middle name,surname,dob,nickname,age,gender,interests/hobbies,fix bordem,F-song,F-music genre,F-film,F-book,F-food,disliked food,disabilities,amount of pets,type of pets,name of pets,education,work,visited places,living location,news interest,news hate,city,country,location key -0,Jamie,,,,,,,,,,,,,,,,,,,,,,,,,Sheffield,United Kingdom,326913 +0,Jamie,,,,,,,,,,,,,,,,,,,,,,,,,Barnsley,United Kingdom,326913 diff --git a/interactions.py b/interactions.py index 2c7adad..1395655 100644 --- a/interactions.py +++ b/interactions.py @@ -471,78 +471,80 @@ def collect_data(user_input, function): data = response.json() #usful data elements - title = data['Search'][0]['Title'].title()#TODO: This returns an error, need to deal with it - year = data['Search'][0]['Year'] - ID = data['Search'][0]['imdbID'] - file_type = data['Search'][0]['Type'] - image_url = data['Search'][0]['Poster'] + try: + title = data['Search'][0]['Title'].title()#TODO: This returns an error, need to deal with it + year = data['Search'][0]['Year'] + ID = data['Search'][0]['imdbID'] + file_type = data['Search'][0]['Type'] + image_url = data['Search'][0]['Poster'] - #call for addional detail using the id - url = f"https://www.omdbapi.com/?apikey=32486892&i={ID}" - detailed_response = requests.get(url) + #call for addional detail using the id + url = f"https://www.omdbapi.com/?apikey=32486892&i={ID}" + detailed_response = requests.get(url) - if detailed_response.status_code == 200: - data = detailed_response.json() - - rated = data['Rated'] - released = data['Released'] - runtime = data['Runtime'] - genre = data['Genre'] - director = data['Director'] - writer = data['Writer'] - actors = data['Actors'] - plot = data['Plot'] - languages = data['Language'] - awards = data['Awards'] - - for rating in data['Ratings']: - if rating['Source'] == 'Rotten Tomatoes': - rate = rating['Value'] + if detailed_response.status_code == 200: + data = detailed_response.json() + + rated = data['Rated'] + released = data['Released'] + runtime = data['Runtime'] + genre = data['Genre'] + director = data['Director'] + writer = data['Writer'] + actors = data['Actors'] + plot = data['Plot'] + languages = data['Language'] + awards = data['Awards'] + + for rating in data['Ratings']: + if rating['Source'] == 'Rotten Tomatoes': + rate = rating['Value'] - try: - #reads currently collected data - with open('data/movie data.json', 'r') as f: - movie_data = json.load(f) - except: - pass + try: + #reads currently collected data + with open('data/movie data.json', 'r') as f: + movie_data = json.load(f) + except: + pass - #writes data to a dictionary - collected_data = { - "Year": released, - "rated": rated, - "runTime": runtime, - "genre": genre, - "director": director, - "writer": writer, - "actors": actors, - "plot": plot, - "languages": languages, - "awards": awards, - "rate": rate} + #writes data to a dictionary + collected_data = { + "Year": released, + "rated": rated, + "runTime": runtime, + "genre": genre, + "director": director, + "writer": writer, + "actors": actors, + "plot": plot, + "languages": languages, + "awards": awards, + "rate": rate} - movie_data[title] = collected_data + movie_data[title] = collected_data - #writes all previous and new data to file - with open('data/movie data.json', 'w') as f: - json.dump(movie_data, f, indent=4) - else: - print(response.status_code) - print(function(user_input)) + #writes all previous and new data to file + with open('data/movie data.json', 'w') as f: + json.dump(movie_data, f, indent=4) + else: + print(response.status_code) + print(function(user_input)) + except KeyError: + pass else: print(chatbot_tools.random_output('no internet')) def release(user_input): - user_input = user_input.title().lstrip().rstrip() + user_input = user_input.title().lstrip().rstrip().replace(' D', '') try: movie_data = movie.read_movie_data() - - movie_data = movie_data[user_input] return (f"{user_input} was released in {movie_data['Year']}") except KeyError: - chatbot_tools.big_guns(user_input) - return '' + movie_data = movie.read_movie_data() + movie_data = movie_data["The " + user_input] + print(f"The {user_input} was released in {movie_data['Year']}") def rate(user_input): try: @@ -552,8 +554,11 @@ def rate(user_input): movie_data = data[user_input] return(f"{user_input} is rated {movie_data['rated']}") except KeyError: - chatbot_tools.big_guns(user_input) - return '' + with open('data/movie data.json', 'r') as f: + data = json.load(f) + + movie_data = data["The " + user_input] + print(f"The {user_input} is rated {movie_data['rated']}") def runtime(user_input): try: @@ -563,8 +568,11 @@ def runtime(user_input): movie_data = data[user_input] return f"{user_input} runs for {movie_data['runTime'].replace('min', 'minutes')}" except KeyError: - chatbot_tools.big_guns(user_input) - return '' + with open('data/movie data.json', 'r') as f: + data = json.load(f) + + movie_data = data["The " + user_input] + print(f"The {user_input} runs for {movie_data['runTime'].replace('min', 'minutes')}") def genre(user_input): try: @@ -574,8 +582,11 @@ def genre(user_input): movie_data = data[user_input] return f"The genre for {user_input} is {movie_data['genre']}" except KeyError: - chatbot_tools.big_guns(user_input) - return '' + with open('data/movie data.json', 'r') as f: + data = json.load(f) + + movie_data = data["The " + user_input] + print(f"The genre for The {user_input} is {movie_data['genre']}") def director(user_input): try: @@ -587,8 +598,13 @@ def director(user_input): directors = ", ".join(list_of_directors[:-1]) + " and " + list_of_directors[-1] return f"The directors for {user_input} are {directors}" except KeyError: - chatbot_tools.big_guns(user_input) - return '' + with open('data/movie data.json', 'r') as f: + data = json.load(f) + + movie_data = data["The " + user_input] + list_of_directors = movie_data['director'].split(', ') + directors = ", ".join(list_of_directors[:-1]) + " and " + list_of_directors[-1] + print(f"The directors for The {user_input} are {directors}") def writer(user_input): try: @@ -600,11 +616,15 @@ def writer(user_input): writers = ", ".join(list_of_writer[:-1]) + " and " + list_of_writer[-1] return f"The directors for {user_input} are {writers}" except KeyError: - chatbot_tools.big_guns(user_input) - return '' + with open('data/movie data.json', 'r') as f: + data = json.load(f) + + movie_data = data["The " + user_input] + list_of_writer = movie_data['writer'].split(', ') + writers = ", ".join(list_of_writer[:-1]) + " and " + list_of_writer[-1] + print(f"The directors for The {user_input} are {writers}") def actor(user_input): - print('running') try: with open('data/movie data.json', 'r') as f: data = json.load(f) @@ -613,9 +633,61 @@ def actor(user_input): list_of_actors = movie_data['actors'].split(', ') actors = ", ".join(list_of_actors[:-1]) + " and " + list_of_actors[-1] return f"The actors for {user_input} are {actors}" - except KeyError: - print('ahh') - #chatbot_tools.big_guns(user_input) - return '' except Exception as e: - print(e) \ No newline at end of file + with open('data/movie data.json', 'r') as f: + data = json.load(f) + + movie_data = data["The " + user_input] + list_of_actors = movie_data['actors'].split(', ') + actors = ", ".join(list_of_actors[:-1]) + " and " + list_of_actors[-1] + print(f"The actors for The {user_input} are {actors}") + + def plot(user_input): + try: + with open('data/movie data.json', 'r') as f: + data = json.load(f) + + movie_data = data[user_input] + plot = movie_data['plot'] + return f"The plot of {user_input} is: {plot}" + except KeyError: + with open('data/movie data.json', 'r') as f: + data = json.load(f) + + movie_data = data["The " + user_input] + plot = movie_data['plot'] + return f"The plot of The {user_input} is: {plot}" + + def languages(user_input): + try: + with open('data/movie data.json', 'r') as f: + data = json.load(f) + + movie_data = data[user_input] + list_of_languages = movie_data['languages'].split(', ') + languages = ", ".join(list_of_languages[:-1]) + " and " + list_of_languages[-1] + return f"The languages for {user_input} are {languages}" + except KeyError: + with open('data/movie data.json', 'r') as f: + data = json.load(f) + + movie_data = data["The " + user_input] + list_of_languages = movie_data['languages'].split(', ') + languages = ", ".join(list_of_languages[:-1]) + " and " + list_of_languages[-1] + print(f"The languages for The {user_input} are {languages}") + + def awards(user_input): + try: + with open('data/movie data.json', 'r') as f: + data = json.load(f) + + movie_data = data[user_input] + awards = movie_data['awards'] + return f"The awards for {user_input} is: {awards}" + except KeyError: + with open('data/movie data.json', 'r') as f: + data = json.load(f) + + movie_data = data["The " + user_input] + awards = movie_data['awards'] + print(f"The awards for The {user_input} is: {awards}") \ No newline at end of file