Skip to content

Instantly share code, notes, and snippets.

@Ejhfast
Last active January 22, 2017 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ejhfast/ea8b7ea5c485f43ead0bbf5101b6933a to your computer and use it in GitHub Desktop.
Save Ejhfast/ea8b7ea5c485f43ead0bbf5101b6933a to your computer and use it in GitHub Desktop.
import empath
import sys
lexicon = empath.Empath()
trump_speech = open(sys.argv[1], "r").read()
obama_speech = open(sys.argv[2], "r").read()
trump_categories = lexicon.analyze(trump_speech, normalize=True)
obama_categories = lexicon.analyze(obama_speech, normalize=True)
def top_categories(categories, n=10):
return sorted(categories.items(), key=lambda x: x[1], reverse=True)[:n]
print(top_categories(trump_categories, 30))
print(top_categories(obama_categories, 30))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment