-----20 Movies Script Visualizations will be done------This could be done for the 1000+ movie script I segmented--- I just randomly chose 20 movie scripts from the segmented movies....
Web scraping of the movie scripts (Over 1000+ movies were scraped from imsdb website)
Movies segmentation into Scenes --> Scene Location, Scene Action/Description, Scene Dialogues, Scene Characters (All the movies scraped were segmented except those that do not follow the "Screenplay format i.e. INT / EXT)"
Character extraction and appearances plot ---> Here, characters were plotted based on how many times they appeared and spoke in each scene and across the movie.
Character Interaction Mapping --> We mapped out the connection between all the characters in the movie and also the interaction between the Top 10 characters in the movie.
Here, we looked at the Most mentioned character based on the Scene dialogues and also the characters each character mention the most in their conversation.
Similar to Number 5., Here looked at who a specific character talks with the most in the Movie.
Emotional and Sentiment Analysis across the whole movie and for each individual character, However for this project we limited it to only the Top 10 characters. ---> This gives us the character's emotion when he/she appears in the movie.
Additional Scene Informations --> Exact Scene Locations, Scenes with dialogs and no dialogs, Scenes that occurred during the Day or in the Night, Scenes location based on Outdoor or Indoor appearances.
Gender Distribution in the movie
*(python Code) Modules for this project: imsbd_moviescript_scraper_AND_Scene_Segmentation.py, dialogue_appearance.py, characters_extract.py, xter_interaction.py, characters_mt.py, emotions.py, movie_info.py, gend_distribution_plot.py*
Tools: Python libraries
#Import all the necessary python modules needed for this analysis
from characters_extract import extract_characters
from dialogue_appearance import scene_dialogues
from xter_interaction import interaction
from emotions import emotions_sentiments
from characters_mt import character_mentions
from gend_distribution_plot import gender
from movie_info import scene_info_plots
import glob
import random
import secrets
import re
import cufflinks as cf
import networkx as net
import itertools
# plotly
from plotly.subplots import make_subplots
import plotly.graph_objects as go
import pandas as pd
import chart_studio.plotly as py
import plotly.graph_objs as go
from plotly import tools
from plotly.offline import init_notebook_mode, iplot
init_notebook_mode(connected=True)
import plotly.express as px
films = []
for f in glob.glob('Films/*'):
film_name = re.sub(r'.pkl|Films\\', '', f)
films.append(film_name)
#Number of Films we segmented into scenes, scene_actions, characters, and characters dialogue
print('Number of films available for Analysis: ', len(films), ' Movies')
Number of films available for Analysis: 1037 Movies
#Random 10 films from the 1000 films scraped from the internet
films_list = random.sample(films, 10)
#Randomly select film to analyze
film = secrets.choice(films_list)
print(film)
Man-On-Fire
##load the scenes, dialogues, characters into dataframe
df_film = pd.read_pickle('Films/' + film + '.pkl')
df_film_dialogue = pd.read_pickle('Dialogues/' + film + '.pkl')
df_film_characters = pd.read_pickle('Characters/' + film + '.pkl')
#Randomly generate 10 scenes from the movie script
df_film.sample(10)
Scene_Names | Scene_action | Scene_Characters | Scene_Dialogue | Contents | |
---|---|---|---|---|---|
84 | INT. AIRPORT MEXICO CITY DAY | The sounds of Samuel's baby grand resonates th... | [PINTA, CREASY, PINTA] | [Frank. Frankie. Pinta whistles., Pinta, we ... | The sounds of Samuel's baby grand resonates t... |
164 | EXT. MEXICO CITY NIGHT | Her car draws up. Her driver exits and opens h... | None | None | Her car draws up. Her driver exits and opens ... |
6 | EXT. CITY SQUARE MEXICO CITY NIGHT | A MERCEDES driving around the square, Eighteen... | None | None | A MERCEDES driving around the square, Eightee... |
85 | INT. SITTING ROOM RAMOS VILLA DAY | Creasy driving. Pinta looking noble and brave. | [CREASY, PINTA, CREASY, PINTA, CREASY, PINTA, ... | [That's strange. Frank was a noshow. Not like ... | Creasy driving. Pinta looking noble and bra... |
179 | INT. VW BUS | Darkness has fallen. Few people are on the str... | [LISA, CREASY, CREASY, PINTA] | [Creasy... Wait., Stay here. If you do somethi... | Darkness has fallen. Few people are on the st... |
47 | INT. CREASY'S ROOM NIGHT | As the mercedes crosses an intersection, a whi... | None | None | As the mercedes crosses an intersection, a wh... |
25 | INT. PINTA'S BEDROOM NIGHT | Brushing her hair, Pinta wanders to the window... | None | None | Brushing her hair, Pinta wanders to the windo... |
180 | INT. LISA'S BEDROOM | Dark spot in the road. Suddenly Police lights,... | [MANZANO, MANZANO, MANZANO, MANZANO] | [I am your chauffeur now, Creasy. Manzano does... | Dark spot in the road. Suddenly Police lights... |
159 | INT. FRANK LLOYD WRIGHT 'KNOCK OFF' MEXICO CITY | Creasy doing laps. He swims the last few meter... | None | None | Creasy doing laps. He swims the last few mete... |
115 | EXT. VIA BUENOS AIRES MEXICO CITY DAY | Bruno lets him in. Nothings been touched. ... | [PINTA'S ROOM, LISA, LISA, CREASY, CREASY, LIS... | [He stands there a moment. His pain entirely h... | Bruno lets him in. Nothings been touched. ... |
#check how many scenes the movie script has
df_film.shape
(183, 5)
#Randomly select characters and their corresponding dialogues
df_film_dialogue.sample(10)
characters | Character_dialogue | |
---|---|---|
595 | CREASY | Blue Bayou is a dream, Pinta. Like you. |
178 | PINTA | There were 24 kidnappings in Mexico City in th... |
609 | CREASY | I need less than standard packing. Can you kno... |
858 | CREASY | Off the top of my head, I don't know what they... |
906 | DANIEL | The girl's. Pinta's. |
402 | PINTA | You are coming with me. |
344 | PINTA | It must be difficult having lots of wives. |
495 | SAMUEL | The realities are I do not have access to this... |
131 | CREASY | Ein Klines Bisschen. A tiny bit. |
893 | CREASY | Yeah. Daniel has a different attitude, a lot m... |
ext = extract_characters(df_film, df_film_dialogue, df_film_characters, film)
mof_characters = ext.extract_character_plot()
dia = scene_dialogues(df_film, film)
df_xter_app = dia.character_appearances(mof_characters)
print('Movie Characters: \n', mof_characters)
Movie Characters: ['CREASY', 'PINTA', 'RAYBURN', 'MANZANO', 'LISA', 'SAMUEL', 'ROSANNA', 'JORDAN', 'JORGE', 'TAZINARI', 'VOICE', 'GUARDIAN TWO', 'DANIEL', "CREASY'S VOICE", 'SISTER ANNA', 'REINA', 'CUSTOMS', 'CHIEF', 'MERCEDES', "PINTA'S VOICE", 'FEMALE GUARDIAN', 'ADJUTANT', "CREASY'S ROOM", 'SLOPPY COP ONE', 'RONSTADT', 'LINDA RONSTADT', 'EVELYN', 'KIDNAPPER', 'COP TWO', 'NURSE', 'PINTA GHOST', 'OLD MAN', 'TECHNICIAN', 'LIVING ROOM', 'BARRIO']
df_creasy_count, df_creasy_dialogue = dia.xter_count_perscene(mof_characters[0])
dia.scene_dialogue_plot(df_creasy_count)
df_pt_count, df_pt_dialogue = dia.xter_count_perscene(mof_characters[1])
dia.scene_dialogue_plot(df_pt_count)
df_ry_count, df_ry_dialogue = dia.xter_count_perscene(mof_characters[2])
dia.scene_dialogue_plot(df_ry_count)
df_cr_pt_count, df_cr_pt_dialogue = dia.xter_count_perscene(mof_characters[:2])
dia.scene_dialogue_plot(df_cr_pt_count)
df_pt_ry_count, df_pt_ry_dialogue = dia.xter_count_perscene(mof_characters[1:3])
dia.scene_dialogue_plot(df_pt_ry_count)
interact = interaction(df_film, film)
graph_list = interact.character_interaction()
# G = net.MultiGraph()
# for scene in graph_list:
# nodes = list(itertools.combinations(scene,2))
# for pair in nodes:
# G.add_edges_from([pair])
# page_ranked_nodes = net.pagerank_numpy(G,0.95)
# net.enumerate_all_cliques(G)
# between_nodes = net.betweenness_centrality(G, normalized=True, endpoints=True)
interact.character_interaction_plot(G, page_ranked_nodes)
#Remember to Re-run the above multigraph code aafter running this code line
graph_list = interact.top10_character_interaction(mof_characters[:10])
interact.character_interaction_plot(G, page_ranked_nodes)
xtr = character_mentions(df_film, mof_characters, film)
xter_mentions = xtr.most_mentioned()
xtr.top_xters_mentions(xter_mentions, 3)
#print(mof_characters)
df_pinta = xtr.talk_about_xters(df_film_dialogue, 'PINTA')
df_cr = xtr.talk_about_xters(df_film_dialogue, 'CREASY')
df_mz = xtr.talk_about_xters(df_film_dialogue, 'MANZANO')
df_creasy = xtr.most_talked_with('CREASY')
df_ry = xtr.most_talked_with(mof_characters[2])
etn = emotions_sentiments(df_film, film)
df_film_sentiment = etn.film_sentiment('darkgoldenrod')
df_film_emotion = etn.film_emotional_arc()
df_top10_emotions = etn.emotional_content_plot(df_film_dialogue, mof_characters, 11)
df_cr_emotions = etn.emotional_arc_xter_plot(df_film_emotion, 'CREASY')
df_ry_emotions = etn.emotional_arc_xter_plot(df_film_emotion, 'RAYBURN')
df_pt_emotions = etn.emotional_arc_xter_plot(df_film_emotion, 'PINTA')
info = scene_info_plots(df_film, film)
info.extract_scene_locations()
info.pie_plots()
gd = gender(mof_characters, film)
df_gender = gd.gender_types(px.colors.sequential.Inferno)
[nltk_data] Downloading package names to C:\Users\Adeboye [nltk_data] Adeniyi\AppData\Roaming\nltk_data... [nltk_data] Package names is already up-to-date!