Skip to content

Instantly share code, notes, and snippets.

@rjwebb
Created January 10, 2017 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rjwebb/c113e62f403587f3d32392310ddba97a to your computer and use it in GitHub Desktop.
Save rjwebb/c113e62f403587f3d32392310ddba97a to your computer and use it in GitHub Desktop.
this is an in-joke
import random
import nltk
from nltk.tokenize import TreebankWordTokenizer
"""
INSTALLATION INSTRUCTIONS:
Install nltk
Use the nltk downloader to install the Penn Treebank corpus
and averaged_perception_tagger
Then run this file with
python reuben.py
this is at your own risk LOL
example usage:
(nltk_env)(14:31:26) bob@computer ~/Code/scrap$ python reuben.py
Type a message, and the ReubenBot will reply. Type 'exit' to close the program.
You: I feel like in this modern era I have become more detached from my fellow human beings. I take the underground every day and I see thousands of faces. I assume they're all real people with real thoughts just like me but there's no way I can ever be sure. If I were to ask them a question of any significance I am sure I would be looked at like a complete idiot or worse still a madman. Perhaps public transportation isn't a good venue for social interaction what with the noise and the heat and so on but I'm sure everyone else in the carriage feels as alone as I do.
Reuben: interaction
You:
"""
print('Type a message, and the ReubenBot will reply. Type \'exit\' to close the program.')
message = ''
while message != 'exit':
message = raw_input('You: ')
text = TreebankWordTokenizer().tokenize(message)
tagged_text = nltk.pos_tag(text)
ws = [w for w, t in tagged_text if t.startswith('N')]
if len(ws) < 1:
print('Please enter another message.')
else:
w = random.choice(ws)
print('Reuben: {}'.format(w))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment