Last active
December 31, 2015 17:09
-
-
Save jlansner/8018083 to your computer and use it in GitHub Desktop.
Richard II Character Breakdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Richard II | |
Total Speeches - 554 | |
Total Lines - 2800 | |
Character Speeches Lines | |
KING RICHARD II 98 758 | |
JOHN OF GAUNT 28 191 | |
HENRY BOLINGBROKE 90 413 | |
THOMAS MOWBRAY 13 135 | |
DUCHESS 4 58 | |
LORD MARSHAL 10 25 | |
DUKE OF AUMERLE 38 85 | |
FIRST HERALD 1 6 | |
SECOND HERALD 1 7 | |
GREEN 10 32 | |
BUSHY 13 39 | |
ALL 1 1 | |
DUKE OF YORK 54 290 | |
QUEEN 25 115 | |
NORTHUMBERLAND 38 142 | |
LORD ROSS 11 22 | |
LORD WILLOUGHBY 8 12 | |
SERVANT 8 17 | |
BAGOT 6 22 | |
HENRY PERCY 12 45 | |
LORD BERKELEY 2 8 | |
CAPTAIN 2 15 | |
EARL OF SALISBURY 3 20 | |
BISHOP OF CARLISLE 6 63 | |
SIR STEPHEN SCROOP 6 37 | |
LADY 6 6 | |
GARDENER 6 52 | |
LORD FITZWATER 6 27 | |
LORD 1 5 | |
DUKE OF SURREY 3 10 | |
ABBOT 2 10 | |
DUCHESS OF YORK 28 94 | |
EXTON 6 21 | |
GROOM 4 12 | |
KEEPER 4 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Richard II</title> | |
<style> | |
body, table, th, td { | |
font-family: arial, helvetica; | |
font-size: 12px; | |
} | |
table { | |
margin-bottom: 10px; | |
} | |
tbody th { | |
text-align: left; | |
} | |
.green { | |
background-color: #0c0; | |
} | |
</style> | |
</head> | |
<body> | |
<?php | |
$xml = simplexml_load_file('rich_ii.xml'); | |
$characters = array(); | |
$lines = array(); | |
$act_number = 1; | |
foreach ($xml->ACT as $act) { | |
$scene_number = 1; | |
foreach ($act->SCENE as $scene) { | |
$speech_number = 0; | |
foreach ($scene->SPEECH as $speech) { | |
$speaker = strtoupper($speech->SPEAKER); | |
$line_count = count($speech->LINE); | |
if (!array_key_exists($speaker,$characters)) { | |
$characters[$speaker]['speeches'] = 0; | |
$characters[$speaker]['lines'] = 0; | |
} | |
$lines['ACT ' . $act_number]['SCENE ' . $scene_number][$speech_number]['Speaker'] = $speaker; | |
$lines['ACT ' . $act_number]['SCENE ' . $scene_number][$speech_number]['Lines'] = $line_count; | |
$characters[$speaker]['speeches']++; | |
$characters[$speaker]['lines'] += $line_count; | |
$speech_number++; | |
} | |
$scene_number++; | |
} | |
$act_number++; | |
} | |
$conversations = array(); | |
foreach ($characters as $char1key => $char1value) { | |
foreach ($characters as $char2key => $char2value) { | |
$conversations[$char1key][$char2key] = 0; | |
$conLines[$char1key][$char2key] = 0; | |
} | |
} | |
$totalSpeeches = 0; | |
$totalLines = 0; | |
foreach ($lines as $act) { | |
foreach ($act as $scene) { | |
$totalSpeeches += count($scene); | |
$currentSpeaker = ""; | |
$previousSpeaker = ""; | |
foreach ($scene as $speech) { | |
$totalLines += $speech['Lines']; | |
$currentSpeaker = $speech['Speaker']; | |
if ($previousSpeaker !== "") { | |
$conversations[$currentSpeaker][$previousSpeaker]++; | |
$conversations[$previousSpeaker][$currentSpeaker]++; | |
$conLines[$currentSpeaker][$previousSpeaker] += $speech['Lines']; | |
$conLines[$previousSpeaker][$currentSpeaker] += $speech['Lines']; | |
} | |
$previousSpeaker = $currentSpeaker; | |
} | |
} | |
} | |
?> | |
<h1>Richard II</h1> | |
<p>Total Speeches - <?php echo $totalSpeeches; ?><br /> | |
Total Lines - <?php echo $totalLines; ?></p> | |
<table border="1"> | |
<thead> | |
<tr> | |
<th>Character</th> | |
<th>Speeches</th> | |
<th>Lines</th> | |
</tr> | |
</thead> | |
<tbody> | |
<?php | |
foreach ($characters as $key => $value) { | |
echo '<tr> | |
<td>' . $key . '</td> | |
<td>' . $value['speeches'] . '</td> | |
<td>' . $value['lines'] . '</td> | |
</tr>'; | |
} | |
?> | |
</tbody> | |
</table> | |
<table border="1"> | |
<thead> | |
<tr> | |
<th>Speaker</th> | |
<?php foreach ($characters as $key => $value) { | |
echo '<th>' . $key . '</th>'; | |
} ?> | |
<th>Total</th> | |
</tr> | |
</thead> | |
<tbody> | |
<?php | |
foreach ($conversations as $char1 => $char2) { | |
?> | |
<tr> | |
<th><?php echo $char1; ?></th> | |
<?php | |
foreach ($char2 as $key => $value) { | |
$lineTotal += $value; | |
if ($value > 0) { | |
echo '<td>' . $value . '</td>'; | |
} else { | |
echo '<td class="green"></td>'; | |
} | |
} | |
echo '</tr>'; | |
} | |
?> | |
</tbody> | |
</table> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment