Shauna's Blog

Word games

Originally at http://www.shaunagm.net/blog/2013/03/word-games/

I’ve been hearing good things about the Capitol Words API for months now, so I decided to try doing something with it. I wrote a script which queries the API for instances of a given word and returns two text files: the first is a compendium of sentences from every time a Republican has said that word (in a given date range), and the second the same but for Democrats. I fed the results into a word cloud generator I found on github, which I modified slightly to suit my purposes.

Some sample output:

“Contraception” - Democrats

“Contraception” - Republicans

“Gun” - Democrats

“Gun” - Republicans

There are apparently other word cloud generators which can compare texts directly and emphasize differences, which might have been better for this exercise, but it’s still pretty cool.

Code is here. Non-coders (or lazy coders who don’t want to clone & try themselves) should feel free to request searches.

And thanks to the good folks on #bostonpython for their help debugging.