Graph Analysis on Shakespeare Play ‘Julies Caesar

Analyzing Character Interactions through NLP and Graph Analysis

Divya Chandana
The AI Guide
7 min readFeb 17, 2021

--

“Et tu, Brute?”

“Et tu, Brute ?”

Introduction

Julies Caesar is a great play. Julies Caesar Play should be called as Brutus. One of the main characters in the play who was the most loyal friend to Caesar. Due to envious conspirators, Brutus was convinced to scheme against Caesar to assassin. Because of Caesars charisma and brutality, excellence as a military leader and European campaigns etc., caused fear in Senate and Pompey that he would get too much power. In-order to stop him from growing they conspired to assassinate Caesar.

Caesar treated Brutus like a own child , when he saw Brutus was one among the traitors he stopped himself defending. Yet, few discern the reason why Brutus and his fellow conspirators betrayed and murdered Caesar. Eventually Brutus got back his repercussions, lost the battle with Antony and leaving Antony Rule the Rome.

This schematic political tragedy keeps me thinking who played major role in the assassination of Julius Caesar, the major character in the Play. Lets have a detailed Graph Analysis to understand who got major role.

Source for Data

This website Gutenberg library has the free ebooks. It provides the the book in different formats I choose .txt format, so that I can easily format and convert this book into my required format to create nodes and edges.

Import Libraries

We have 5 Acts and in each act has different scenes. Entire book is in this format , everything divided in to scenes.

Contents of The tragedy of Julius Caesar

Data Cleaning

Dividing the book into scenes using the keyword. We got 19 scenes totally from the output which matches the scenes count in the contents

Gathering all the Characters in to array from the scene1 , which gives characters list.

Characters in the play

Helper functions to parse the all the Acts and scenes

Cleaning unwanted text

# cleaning data , unwanted text
print(scenes[18].split(‘***’)[0])

cleaning more. Finding enter and exit of person from a scene .

input each and scene and the respective act of scene co appearances dictionary to the helper function which results in the appearances count of the characters in the given scene

helper function to check duplicates and add new characters appear in the scene

Counting how many times the character co-appeared with another character

Edges

If number greater than 0 it means the characters appeared in one or more scenes together. Weight of edges are determined by how often characters speak with each other in the same scene.

Nodes

scene counts is the number of scenes each character appeared

Network analysis using networkX

Create Graph by creating Nodes from Scene_counts

NodeView((‘Caesar’, ‘Lepidus’, ‘Publius’, ‘Brutus’, ‘Cassius’, ‘Casca’, ‘Trebonius’, ‘Ligarius’, ‘Cimber’, ‘Cinna’, ‘Flavius’, ‘Marullus’, ‘Artemidorus’, ‘Lucilius’, ‘Titinius’, ‘Messala’, ‘Cato’, ‘Volumnius’, ‘Varro’, ‘Clitus’, ‘Claudius’, ‘Strato’, ‘Lucius’, ‘Dardanius’, ‘Pindarus’, ‘Calphurnia’, ‘Portia’, ‘Antony’))

Add edges to the node, for each co-appearance of the characters in the scene add it as node and count as weight

Structure of graph

Centrality

edge betweenness, by definition an edge is the sum of the fraction of all-pairs shortest paths that pass through edge. This results dictionary of edges with betweenness centrality value

load centrality , by definition a node is the fraction of all shortest paths that pass through that node. the result is the dictionary of nodes with centrality value.

Successors of node is list of all nodes that have directed edge towards given node to result node. here we got list of successor node for Caesar

Position nodes using Fruchterman-Reingold force-directed algorithm.The algorithm simulates a force-directed representation of the network treating edges as springs holding nodes close, while treating nodes as repelling objects, sometimes called an anti-gravity force. Simulation continues until the positions are close to an equilibrium.

out_edges results the list of edges

Important Nodes

betweenness centrality

measure of centrality in a graph based on shortest paths. Its a general measure of centrality. Here, higher Betweenness centrality means the node have more control over the network, because more information will pass through that node. In our case Brutus has the highest 0.379

Once positioning of each node according to their weights betweenness of centrality and the Node size is proportional to the importance. The final Network of the Play Julies Caesar all the characters look like this.

Network of Characters

To concentrate on main characters these guys are the winners of treachery.

Bugs encountered

I faced issues while cleaning data with regular expressions. there is no proper way to get the data the only way is Brute-Force It has to be trail and error.

While dealing with list I got couple of times index out of bound exception, I fixed by checking proper index of the particular list

Conclusion

From the Network it is very clear that, Brutus played the huge role to assassin Caesar. However due to political moral he lost his moral and played crucial role as a backstabber. Even though he faced repercussions, after that he continued having the guilt. Our network showed relevant information from the book. we can easily relate the story, The limitations in this approach is, I cannot cluster supporters vs backstabbers of Caesar. I might consider working in this in future.

One of the Brutus reasons might be this lol

The End

CINNA.
O Caesar, —

CAESAR.
Hence! wilt thou lift up Olympus?

DECIUS.
Great Caesar, —

CAESAR.
Doth not Brutus bootless kneel?

CASCA.
Speak, hands, for me!

[Casca stabs Caesar in the neck. Caesar catches hold of his arm. He is then stabbed by several other Conspirators, and at last by Marcus Brutus.]

CAESAR.
Et tu, Brute? — Then fall, Caesar!

[Dies. The Senators and People retire in confusion.]

CINNA.
Liberty! Freedom! Tyranny is dead!
Run hence, proclaim, cry it about the streets.

CASSIUS.
Some to the common pulpits and cry out,
“Liberty, freedom, and enfranchisement!”

BRUTUS.
People and Senators, be not affrighted.
Fly not; stand still; ambition’s debt is paid.

CASCA.
Go to the pulpit, Brutus.

DECIUS.
And Cassius too.

BRUTUS.
Where’s Publius?

CINNA.
Here, quite confounded with this mutiny.

METELLUS.
Stand fast together, lest some friend of Caesar’s
Should chance —

BRUTUS.
Talk not of standing. Publius, good cheer!
There is no harm intended to your person,
Nor to no Roman else. So tell them, Publius.

CASSIUS.
And leave us, Publius; lest that the people
Rushing on us, should do your age some mischief.

BRUTUS.
Do so; and let no man abide this deed
But we the doers.

--

--