-----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)
Alien-vs.-Predator
##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 | |
---|---|---|---|---|---|
127 | INT. RYUSHI STATION AUTOSHOP CRAWLER CABIN | THOMAS is laidout in the back seat of the craw... | [GUTTIEREZ] | [Rob? We got problems. ] | THOMAS is laidout in the back seat of the cra... |
149 | INT. RYUSHI STATION COMMAND CENTER | Everybody in admin looks tense. | [HIROKO] | [Three... ] | Everybody in admin looks tense. HIROKO Three... |
248 | EXT. SWAMP DAWN | The sun begins to rise as HIROKO exits the hel... | [HIROKO, BROKEN TUSK, VOICE, HIROKO] | [Hold on. This is gonna hurt some. HIROKO get... | The sun begins to rise as HIROKO exits the he... |
242 | EXT. CHOPPER PREDAWN | The chopper clips the tree boughs, and bounces. | None | None | The chopper clips the tree boughs, and bounces. |
15 | INT. RYUSHI STATION EXECUTIVE OFFICE | HIROKO NOGUCHI is sweating heavily, a black fo... | [HIROKO, HIROKO, CASSIE, HIROKO, CASSIE, HIROKO] | [Fuck Holo off. The SWORDSMEN immediately fli... | HIROKO NOGUCHI is sweating heavily, a black f... |
145 | INT. RYUSHI STATION CRANE CAB NIGHT | HIROKO enters the cab at a run. She flips a r... | [HIROKO, HIROKO, HIROKO] | [Access panel... access panel... She finds it.... | HIROKO enters the cab at a run. She flips a ... |
83 | INT. RYUSHI STATION COMMAND CENTER | PARSONS sits bolt upright in his chair as the ... | [PARSONS] | [Oh my God... ] | PARSONS sits bolt upright in his chair as the... |
181 | EXT. RYUSHI STATION BIG BERTHA NIGHT | GUTTIEREZ and DE VRIES exit the crawler in a b... | [DE VRIES] | [C amon, man Let's shag it GUTTIEREZ begins c... | GUTTIEREZ and DE VRIES exit the crawler in a ... |
5 | EXT. SPACE | A large spacecraft is suspended in orbit aroun... | None | None | A large spacecraft is suspended in orbit arou... |
159 | INT. FIRST CRAWLER CAB | GUTTIEREZ pushes forward on the crawler's cont... | None | None | GUTTIEREZ pushes forward on the crawler's con... |
#check how many scenes the movie script has
df_film.shape
(249, 5)
#Randomly select characters and their corresponding dialogues
df_film_dialogue.sample(10)
characters | Character_dialogue | |
---|---|---|
14 | KAMEN | Just got back. Missed anything? |
256 | CASSIE | The door's sealed from inside. Doc Revna's in... |
385 | HIROKO | Get the door KAMEN hastily slaps the 'close' b... |
224 | REVNA | Sure. She goes to fetch a cup. |
591 | HIROKO | Come on... She bears down on the trigger again... |
167 | KAMEN | Okay. Watch were you point it... |
154 | BEAUVAIS | We have got no option. We are gonna have to g... |
553 | PARSONS | Alright, let's open her up. Carefully, now...... |
295 | GUTTIEREZ | Next time you have a thought like that? Keep i... |
176 | KAMEN | Yeah. Found it curled up in a corner of the t... |
ext = extract_characters(df_film, df_film_dialogue, df_film_characters, film)
movie_characters = ext.extract_character_plot()
dia = scene_dialogues(df_film, film)
df_xter_app = dia.character_appearances(movie_characters)
print('Movie Characters: \n', movie_characters)
Movie Characters: ['HIROKO', 'GUTTIEREZ', 'KAMEN', 'PARSONS', 'CASSIE', 'DE VRIES', 'YORK', 'ACKLAND', 'DILLER', 'URIOSTE', 'THOMAS', 'REVNA', 'BEAUVAIS', 'DRISCOLL', 'MINH', 'MATT', 'PREDATOR', 'GREASE MONKEY', 'REDHEADED GIRL', 'BROKEN TUSK']
df_1st_count, df_1st_dialogue = dia.xter_count_perscene(movie_characters[0])
dia.scene_dialogue_plot(df_1st_count)
df_2nd_count, df_2nd_dialogue = dia.xter_count_perscene(movie_characters[1])
dia.scene_dialogue_plot(df_2nd_count)
df_third_count, df_third_dialogue = dia.xter_count_perscene(movie_characters[2])
dia.scene_dialogue_plot(df_third_count)
df_2_count, df_2_dialogue = dia.xter_count_perscene(movie_characters[:2])
dia.scene_dialogue_plot(df_2_count)
df_3_count, df_3_dialogue = dia.xter_count_perscene(movie_characters[1:3])
dia.scene_dialogue_plot(df_3_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(movie_characters[:10])
interact.character_interaction_plot(G, page_ranked_nodes)
xtr = character_mentions(df_film, movie_characters, film)
xter_mentions = xtr.most_mentioned()
xtr.top_xters_mentions(xter_mentions, 5)
print(movie_characters)
['HIROKO', 'GUTTIEREZ', 'KAMEN', 'PARSONS', 'CASSIE', 'DE VRIES', 'YORK', 'ACKLAND', 'DILLER', 'URIOSTE', 'THOMAS', 'REVNA', 'BEAUVAIS', 'DRISCOLL', 'MINH', 'MATT', 'PREDATOR', 'GREASE MONKEY', 'REDHEADED GIRL', 'BROKEN TUSK']
df_hi = xtr.talk_about_xters(df_film_dialogue, 'HIROKO')
df_gui = xtr.talk_about_xters(df_film_dialogue, 'GUTTIEREZ')
df_CK = xtr.talk_about_xters(df_film_dialogue, 'KAMEN')
df_hir = xtr.most_talked_with('HIROKO')
df_kam = xtr.most_talked_with(movie_characters[2])
etn = emotions_sentiments(df_film, film)
df_film_sentiment = etn.film_sentiment('darkslategray')
df_film_emotion = etn.film_emotional_arc()
df_top10_emotions = etn.emotional_content_plot(df_film_dialogue, movie_characters, 11)
df_hik_emotions = etn.emotional_arc_xter_plot(df_film_emotion, 'HIROKO')
df_gut_emotions = etn.emotional_arc_xter_plot(df_film_emotion, 'GUTTIEREZ')
df_kam_emotions = etn.emotional_arc_xter_plot(df_film_emotion, 'KAMEN')
info = scene_info_plots(df_film, film)
info.extract_scene_locations()
info.pie_plots()
gd = gender(movie_characters, film)
df_gender = gd.gender_types(px.colors.sequential.Viridis)
[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!