aboutsummaryrefslogtreecommitdiff
path: root/wordcount/multilang/resources/sentencespout.py
blob: a75f37da958bdebd78e94d2d473374bb46d2b881 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import storm
import random
# Define some sentences
SENTENCES = """
the cow jumped over the moon
an apple a day keeps the doctor away
four score and seven years ago
snow white and the seven dwarfs
i am at two with nature
""".strip().split('\n')

class SentenceSpout(storm.Spout):
    # Not much to do here for such a basic spout
    def initialize(self, conf, context):
        self._conf = conf
        self._context = context

        storm.logInfo("Spout instance starting...")

    # Process the next tuple
    def nextTuple(self):
        # Emit a random sentence
        sentence = random.choice(SENTENCES)
        storm.logInfo("Emiting %s" % sentence)
        storm.emit([sentence])

# Start the spout when it's invoked
SentenceSpout().run()