-
-
Save muranava/9926ab740eab048bce68346bcdcc46d3 to your computer and use it in GitHub Desktop.
Script for separating the third presidential debate by speaker
This file contains hidden or 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
<?php | |
#Thanks to the VoyantTools Twitter (@VoyantTools) for the original php script!) | |
$dirname = dirname(__FILE__); | |
$filename = "debate3.txt"; #assumes you have https://gist.github.com/paigecm/52ce175a98a3f0baa76dc0847c445b5e | |
$speaker = ""; $speeches = array(); | |
foreach(file("$dirname/$filename") as $line) { | |
$withoutname = preg_replace("/^(WALLACE|CLINTON|TRUMP):/","", $line); | |
if ($line!=$withoutname) { | |
$speaker = substr($line, 0, strpos($line, ":")); | |
} | |
if (trim($withoutname) && trim($withoutname)!="(APPLAUSE)") { | |
$speeches[$speaker] .= $withoutname; | |
} | |
} | |
foreach($speeches as $speaker => $speech) { | |
file_put_contents("$dirname/$speaker.txt", $speech); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment