Here’s one purely for fun – a wordcloud built from the Supreme Court’s opinion on Arizona et al. v United States.  Word clouds, though certainly not the most scientific of visualization techniques, are often engaging and “fun” ways to lead into discussion on NLP or topic modeling.

Arizona  et al. v United States wordcloud

Arizona et al. v United States wordcloud

The process to generate this image is entirely automated with Tika and R.  We convert the PDF to text, strip, normalize, and stopword the text, then convert to histogram and plot as a wordcloud. Here’s the snippet below:

$ java -jar /opt/tika/tika.jar --text arizona_et_al_v_united_states.pdf >  arizona_et_al_v_united_states.txt
$ R
>  library(tm)
>  library(wordcloud)
>  library(RColorBrewer)
>  corpus <- Corpus(DirSource(pattern="*.txt"))
>  corpus <- tm_map(tm_map(tm_map(corpus, removePunctuation), tolower), function(x) removeWords(x, stopwords("english")))
>  tdMatrix <- as.matrix(TermDocumentMatrix(corpus))
>  tdMatrix <- sort(rowSums(tdMatrix), decreasing=T)
>  freqDF <- data.frame(words=names(tdMatrix), freq=tdMatrix)
>  colorPalette <- brewer.pal(8, "RdBu")
>  png(file="arizona_v_usa_wordcloud.png", bg="black")
>  wordcloud(freqDF$words, freqDF$freq, scale=c(8, 0.25), min.freq=10, random.order=F, rot.per=0.2, colors=colorPalette)