/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package at.illecker.storm.examples.simplesentimentanalysis.bolt;

import java.util.Map;

import twitter4j.Status;
import backtype.storm.task.OutputCollector;
import backtype.storm.task.TopologyContext;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.topology.base.BaseRichBolt;
import backtype.storm.tuple.Fields;
import backtype.storm.tuple.Tuple;
import backtype.storm.tuple.Values;

public class SplitTweetBolt extends BaseRichBolt {
  private static final long serialVersionUID = -1743985516496636972L;
  private OutputCollector m_collector;

  public void declareOutputFields(OutputFieldsDeclarer declarer) {
    declarer.declare(new Fields("word")); // key of output tuples
  }

  public void prepare(Map config, TopologyContext context,
      OutputCollector collector) {
    this.m_collector = collector;
  }

  public void execute(Tuple tuple) {
    Status status = (Status) tuple.getValueByField("tweet");
    String tweetText = status.getText();
    // LOG.info("@" + status.getUser().getScreenName() + " - " + tweetText);
    String[] words = tweetText.split(" ");
    for (String word : words) {
      this.m_collector.emit(tuple, new Values(word));
    }
    this.m_collector.ack(tuple);
  }
}

@@ -1857,16 +1857,92 @@
 tText);%0A
+    tweetText = tweetText.replaceAll(%22%5C%5Cp%7BPunct%7D%7C%5C%5Cn%22, %22 %22).toLowerCase();%0A%0A
     Stri
@@ -2004,24 +2004,81 @@
  : words) %7B%0A
+      word = word.trim();%0A      if (!word.isEmpty()) %7B%0A  
       this.m
@@ -2119,16 +2119,24 @@
 word));%0A
+      %7D%0A
     %7D%0A  

Update SimpleSentimentAnalysis (trim words)