Skip to content

Instantly share code, notes, and snippets.

@BrianHicks
Last active December 12, 2015 05:08
Show Gist options
  • Save BrianHicks/4719405 to your computer and use it in GitHub Desktop.
Save BrianHicks/4719405 to your computer and use it in GitHub Desktop.
@router.node(('bigram',))
def bigrams(msg):
'get bigrams from a document'
prev = None
for word in msg.document.strip().split(' '):
yield (prev, word)
prev = word
@router.node(('bigram', 'frequency'), 'bigrams')
def count_bigrams(msg):
'count bigrams'
count = redis.incrby(' '.join(msg.bigram), 1)
return bigram, count
@router.node(('tweet',), 'some_other_node')
def filter_tweets(msg):
'filter tweets based on content'
if BAD_WORD in msg.tweet:
return NoResult
return msg.tweet
@router.node(('word',))
def get_words(msg):
'get the words in a document'
for word in msg.document.strip().split(' '):
if word:
yield word
@router.node(('word', 'count'), 'package.other_func')
def count_words(msg):
'get the count of a word'
count = redis_conn.incrby(msg.word, 1)
return msg.word, count
from emit import Router
router = Router()
# or
from emit.router.rq import RQRouter
from redis import Redis
router = RQRouter(Redis())
@router.node(('sentence',))
def sentences(msg):
'naively split a document into sentences'
key = '. ' # dot space space
for sentence in msg.document.strip().split(key):
yield sentence
@router.node(('sentence', 'score'), 'sentences')
def sentiment(msg):
'analyze sentiment'
# NLTK magic here
return msg.sentence, sentiment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment