Skip to content

Instantly share code, notes, and snippets.

@schwanksta
Created March 27, 2013 20:41
Show Gist options
  • Save schwanksta/5257833 to your computer and use it in GitHub Desktop.
Save schwanksta/5257833 to your computer and use it in GitHub Desktop.
Quick and dirty script to parse a Supreme Court transcript and output a JSON file of [speaker, words]
import re
import json
ws_re = re.compile("\s+")
line_num_re = re.compile("\s\d+\s{2,}", re.M)
# first, pdftotext -layout <pdf> <text>
with open("12-307_jnt1.txt", "r") as f:
data = f.read()
exclude = (
"Alderson Reporting Company",
"Official - Subject to Final Review",
)
data = re.sub(line_num_re, "", data)
for xc in exclude:
data = data.replace(xc, "")
data = re.sub(ws_re, " ", data)
data_split = re.split('([A-Z+.]{3,} [A-Z ]+):', data)
del data_split[0]
pairs = zip(data_split[0::2], data_split[1::2])
js = json.dumps(pairs)
with open("sc-doma.json", "w") as f:
f.write(js)
@schwanksta
Copy link
Author

After you dump the text with pdftotext, you'll want to clear away anything that's not direct conversation (the top of the doc, the bottom of the doc, and a few ALL CAP PHRASES in the middle of the text). Then run the script and voila.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment