- The text I am using is below.
So far, I have imported the text:
tempest.v <- scan("data/plainText/tempest.txt", what="character", sep="\n")
Identified where all of the speaker positions begin:
speaker.positions.v <- grep('^[^\\s]\\w+:', tempest.v)
Added a marker at the end of the text:
tempest.v <- c(tempest.v, "END:")
Here's the part where I'm having difficulty (assuming what I've already done is useful):
for(i in 1:length(speaker.positions.v)){
if(i != length(speaker.positions.v)){
speaker.name <- debate.v[speaker.positions.v[i]]
speaker.name <- strsplit(speaker.name, ":")
speaker.name <- unlist(speaker.name)
start <- speaker.positions.v[i]+1
end <- speaker.positions.v[i+1]-1
speaker.lines.v <- debate.v[start:end]
}
}
Now I have variable speaker.name that has, on the left-hand side of the split, the name of the character who is speaking. The right-hand side of the split is the dialogue only up through the first line break.
I set the start of the dialogue block at position [i]+1 and the end at [i+1]-1 (i.e., one position back from the beginning of the subsequent speaker's name).
Now I have a variable, speaker.lines.v with all of the lines of dialogue for that speaker for that one speech.
How can I collect all of Prospero's then Miranda's (then any other character's) dialogue into a single (list? vector? data frame?) for analysis?
Any help with this would be greatly appreciated.
Happy New Year!
--- *TEXT ---
*Miranda: If by your art, my dearest father, you have Put the wild waters in this roar, allay them. The sky, it seems, would pour down stinking pitch, But that the sea, mounting to the welkin's cheek, Dashes the fire out. O, I have suffered With those that I saw suffer -- a brave vessel,
Who had, no doubt, some noble creature in her, Dash'd all to pieces. O, the cry did knock Against my very heart. Poor souls, they perish'd. Had I been any god of power, I would Have sunk the sea within the earth or ere It should the good ship so have swallow'd and The fraughting souls within her.
Prospero: Be collected: No more amazement: tell your piteous heart There's no harm done.
Miranda: O, woe the day!
Prospero: No harm. I have done nothing but in care of thee, Of thee, my dear one, thee, my daughter, who Art ignorant of what thou art, nought knowing Of whence I am, nor that I am more better Than Prospero, master of a full poor cell, And thy no greater father.
Miranda: More to know Did never meddle with my thoughts.
Prospero: 'Tis time I should inform thee farther. Lend thy hand, And pluck my magic garment from me. So:
[Lays down his mantle]
Lie there, my art. Wipe thou thine eyes; have comfort. The direful spectacle of the wreck, which touch'd The very virtue of compassion in thee, I have with such provision in mine art So safely ordered that there is no soul— No, not so much perdition as an hair Betid to any creature in the vessel Which thou heard'st cry, which thou saw'st sink. Sit down; For thou must now know farther.
--- END TEXT ---