-----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)
Antz
##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 | |
---|---|---|---|---|---|
33 | EXT. INSECTOPIA, TOP OF CAN NIGHT | As Ant Team Six lands and takes up position ab... | [TRACKER ANT, MANDIBLE, COMMANDO, MANDIBLE] | [Yesyesyesyesyes One of the commandoes puts h... | As Ant Team Six lands and takes up position a... |
9 | INT. TOWN CENTER NIGHT | The ant army has gathered in a huge HALL in fr... | [FORMICA, FORMICA, FORMICA, FORMICA, COLONEL, ... | [First of all, let me make one thing clear. N... | The ant army has gathered in a huge HALL in f... |
5 | INT. BALA'S QUARTERS DAY | Bala enters, followed by her handmaidens, who ... | [HANDMAIDEN, HANDMAIDEN, HANDMAIDEN, BALA, HAN... | [swooning over General Formica The General's b... | Bala enters, followed by her handmaidens, who... |
28 | EXT. GRASS JUNGLE DAY | Z and Bala are lost, wandering through the grass | [BALA, BALA, BALA] | [I swear, we have passed this blade of grass t... | Z and Bala are lost, wandering through the gr... |
37 | INT. FORMICA'S CHAMBERS DAY | Formica sits at his desk, going over some plan... | [FORMICA, BALA, FORMICA, BALA, FORMICA, BALA, ... | [Princess Bala. Good. Where's Z? Bala replies... | Formica sits at his desk, going over some pla... |
11 | EXT. TERRAIN NEAR TERMITE STUMP NIGHT | Z looks up to see...looming high above them...... | [COLONEL, BARBATUS, BARBATUS, BARBATUS, COLONE... | [ATTAAAAAAAAACK The front line of ants starts ... | Z looks up to see...looming high above them..... |
20 | INT. KITCHEN DAY | Z backs up into the kitchen, still pulling Bal... | None | None | Z backs up into the kitchen, still pulling Ba... |
3 | INT. TOWN CENTER DAY | The huge, spacious main chamber of the colony.... | [GENERAL FORMICA, CARPENTER, GENERAL FORMICA, ... | [Cut the chitchat down there We have spoiled t... | The huge, spacious main chamber of the colony... |
40 | INT. MID SKYLIGHT TUNNEL | Bala, tied and gagged. She's at the point in ... | None | None | Bala, tied and gagged. She's at the point in... |
16 | EXT. ANT MOUND DAY | Some guard ants are looking out across the san... | [GUARD ANT] | [Look They are back The army's back Alert t... | Some guard ants are looking out across the sa... |
#check how many scenes the movie script has
df_film.shape
(57, 5)
#Randomly select characters and their corresponding dialogues
df_film_dialogue.sample(10)
characters | Character_dialogue | |
---|---|---|
115 | FORMICA | Dammit, I am proud to be an ant. he looks out ... |
184 | FORMICA | May I cut in? Z Oh, of course |
404 | QUEEN | We are Z. Now, the workers are all shouting th... |
71 | WEAVER | Poor guy's had one too many scouting missions.... |
97 | SOLDIER | An individual? Never heard of it. |
281 | BALA | You were right...you were right Z, it's beauti... |
125 | ANT SOLDIERS | to the tune of When Johnny Comes Marching Home... |
75 | BALA | And do Princesses do improper things? |
288 | MALE WASP | They are Eurotrash, dear. We hear a loud RUMBL... |
220 | WORKER | I heard about this guy. turning to the other w... |
ext = extract_characters(df_film, df_film_dialogue, df_film_characters, film)
antz_characters = ext.extract_character_plot()
dia = scene_dialogues(df_film, film)
df_xter_app = dia.character_appearances(antz_characters)
print('Movie Characters: \n', antz_characters)
Movie Characters: ['BALA', 'FORMICA', 'WEAVER', 'AZTECA', 'QUEEN', 'BARBATUS', 'WORKER', 'HANDMAIDEN', 'MANDIBLE', 'CARPENTER', 'MALE WASP', 'MOTIVATIONAL COUNSELLOR', 'FLY', 'TRACKER ANT', 'COLONEL', 'ANT OFFICER', 'FOREMAN', 'GENERAL FORMICA', 'SOLDIER', 'CRICKET', 'DRUNK SCOUT', 'BARKER', 'ANT SOLDIERS', 'FEMALE WASP', 'BEETLE', 'LADYBUG', 'SOLDIER ANT', 'WORKERS', 'WASP']
df_bala_count, df_bala_dialogue = dia.xter_count_perscene(antz_characters[0])
dia.scene_dialogue_plot(df_bala_count)
df_fm_count, df_fm_dialogue = dia.xter_count_perscene(antz_characters[1])
dia.scene_dialogue_plot(df_fm_count)
df_wv_count, df_wv_dialogue = dia.xter_count_perscene(antz_characters[2])
dia.scene_dialogue_plot(df_wv_count)
df_fm_bl_count, df_fm_bl_dialogue = dia.xter_count_perscene(antz_characters[:2])
dia.scene_dialogue_plot(df_fm_bl_count)
df_fm_wv_count, df_fm_wv_dialogue = dia.xter_count_perscene(gotd_characters[1:3])
dia.scene_dialogue_plot(df_fm_wv_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(gotd_characters[:10])
interact.character_interaction_plot(G, page_ranked_nodes)
xtr = character_mentions(df_film, antz_characters, film)
xter_mentions = xtr.most_mentioned()
xtr.top_xters_mentions(xter_mentions, 5)
print(antz_characters)
['BALA', 'FORMICA', 'WEAVER', 'AZTECA', 'QUEEN', 'BARBATUS', 'WORKER', 'HANDMAIDEN', 'MANDIBLE', 'CARPENTER', 'MALE WASP', 'MOTIVATIONAL COUNSELLOR', 'FLY', 'TRACKER ANT', 'COLONEL', 'ANT OFFICER', 'FOREMAN', 'GENERAL FORMICA', 'SOLDIER', 'CRICKET', 'DRUNK SCOUT', 'BARKER', 'ANT SOLDIERS', 'FEMALE WASP', 'BEETLE', 'LADYBUG', 'SOLDIER ANT', 'WORKERS', 'WASP']
df_bala = xtr.talk_about_xters(df_film_dialogue, 'BALA')
df_fm = xtr.talk_about_xters(df_film_dialogue, 'FORMICA')
df_queen = xtr.talk_about_xters(df_film_dialogue, 'QUEEN')
df_wv = xtr.most_talked_with('WEAVER')
df_az = xtr.most_talked_with(antz_characters[3])
etn = emotions_sentiments(df_film, film)
df_film_sentiment = etn.film_sentiment('darkorchid')
df_film_emotion = etn.film_emotional_arc()
df_top10_emotions = etn.emotional_content_plot(df_film_dialogue, antz_characters, 11)
df_ba_emotions = etn.emotional_arc_xter_plot(df_film_emotion, 'BALA')
df_WV_emotions = etn.emotional_arc_xter_plot(df_film_emotion, 'WEAVER')
df_fm_emotions = etn.emotional_arc_xter_plot(df_film_emotion, 'FORMICA')
info = scene_info_plots(df_film, film)
info.extract_scene_locations()
info.pie_plots()
gd = gender(antz_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!