Making a Prompter – part 1


I’ve been trying to teach myself to code ever since I took a year out between my MPhil and my PhD, way back in 2014. Teaching oneself to code, however, is very different from my other autodidactic project: teaching myself German. Whereas I can happily learn little bits of German, memorize grammar and vocabulary and use them to read, write or speak every now and then, I find that the only way one learns to code is to have a project. Programming languages are very different to human tongues: the former are totally instrumental, the latter not so much. I learn enough code to do a project, and, by doing enough projects, I gradually build up a facility in the particularly logical way one must talk to computers.

Back in 2014, my first project involved learning javascript, which – along with some basic HTML I picked up as an undergraduate – allowed me to build The Verb Gymnasium. This simple site, now hosted on the same server as this blog, quizzes you on the form of two Ancient Greek verbs. Making this thing both taught me rudimentary javascript and, while coding and afterwards, helped me memorize the key conjugations of a long-dead but very beautiful language.

Enough with the preamble. The PhD and my first years at Newcastle meant that my coding stayed on the backburner for half a decade: I’d do a bit every now and then, often to repair a website I was responsible for (I credit the British Shakespeare Association with my knowledge of PHP, for example), but I lacked a project to carry me to the next level. This all changed one afternoon in the Armstrong Building when I was sitting in one of the first meetings of the ATNU project. ATNU stands for Animating Texts at Newcastle University (more details here), and this meeting was to gather ideas for the project’s first funding bids. I didn’t have any, but I did – rather flippantly at the time – suggest that it would be cool to build a website which replicated the practices of an early modern prompter: a cyborg John Downes or William Hopkins, if you will.

I didn’t think much more of this for a while. Teaching and other commitments got in the way, until we all went on strike over the proposal of some extraordinarily misguided changes to our pensions. When not standing on the picket lines, I decided to do some work on building a Cyborg Prompter. This creation would perform one of the key roles of the prompter: producing the ‘parts’ for the actors in the play, where a part consisted only of a character’s lines, preceded by a one- or two-word cue.

My first decision was to choose to write this programme in Python, a language that everyone tells me is an excellent one for a beginner who is serious about improving their skills. After downloading some things, and reading many more:


#adding in modules
from bs4 import BeautifulSoup
import urllib2
#making soup from a page
quote_page = 'https://quod.lib.umich.edu/e/ecco/004798016.0001.000?rgn=main;view=fulltext;rgn1=author;q1=centlivre'
page = urllib2.urlopen(quote_page)
soup = BeautifulSoup(page, 'html.parser')
#creating a part
#finds speeches, including character headings
speeches = soup.find_all("div",{"class":"sp"})
#sets the character to the person who speaks the first speech
character=speeches[1].contents[1]
#sets up the part as an object for the lines and cues to be added to
the_part=[]
#goes through each speech (including speech heading)
for speech in speeches:
#when it finds a speech spoken by the character
if speech.contents[1]==character:
#finds the position of the speech spoken before the character's
predecessor_number=speeches.index(speech)-1
predecessor_speech=speeches[predecessor_number]
cuetext=predecessor_speech.contents[3]
#loads the speech, selects the div containing just the spoken words (a little imperfectly), splits up that div and then takes the last few words to form a cue.
cuewords=str(cuetext)
cuelist=cuewords.split(' ')
cueposition=len(cuelist)-1
#appends the cue to the part
the_cue='------------------'+cuelist[cueposition]
the_part.append(the_cue)
the_part.append(speech)
#appends the line to the part
mystring = ' '.join(the_part)
#prints the part to a file
myfile = open('C:\Users\jam3s\OneDrive\Coding\Cyborg Prompter\part.html','w')
myfile.write(mystring)
myfile.close

If you’re not familiar with Python (and maybe if you are), this must look pretty messy. If you follow the comments (the lines beginning with ‘#’) you’ll get a sense of what the programme is doing. There are a few key steps:

  1. Pull the text of a play into the programme (done here with the BeautifulSoup module, pointed at an Oxford Text Archive edition of The Basset Table in HTML);
  2. Find all of the speeches in the play;
  3. Go through each speech in turn; check to see whether the speech is spoken by a specific character or not; if it is then…
  4. …find the speech immediately before this one, turn the words in that speech into a list, take the last word in that list (the ‘cue word’) and then use that to make the cue (by adding the ‘cue word’ on the end of ‘—–‘)
  5. Print the cue to a document, then print the speech, and then start again on the next speech until there are no speeches left.

The time I spent putting this together was time in which I familiarized myself with modules as well as the basic workings of Python (its use of whitespace, its syntax, etc.). I also worked out the basic steps of what this programme would need to do.

My efforts worked! But only in a very limited way. There were many shortcomings: I had to point this programme at a text rendered in HTML, I had no user interface so that others could run the programme easily, and – most crucially of all – the text output of this code did not always give me what I want, as it often ran into encoding issues. One of the things I always find when I’m programming is that it makes me discover a great many things that I overlooked when announcing the project. For example: what if one character goes by different names? what if the text is encoded in an unusual format? what if the character is the first person to speak in an act (and therefore does not need a cue)? And so on, and so on.

The strike was ending. I saved the code, and didn’t think about it for a while.


2 responses to “Making a Prompter – part 1”

  1. […] This post continues from part one. Term finished, and I had a little bit of headroom to start thinking about my coding again. I tried to polish my code, but couldn’t solve all of its problems. I tried a different approach, using XSLT to change how a TEI-XML version of a play was displayed, such that it showed only a single part. I couldn’t get this to work either, although I am certain that this method would probably have been the best way of doing things. As it was, the one thing I did take away from my fiddling around with XSLT and TEI was the very impressive TEI Boilerplate, which converts TEI-XML into HTML, and so to a version that renders nicely in a web browser. […]