Changes between Initial Version and Version 1 of waue/2009/0715


Ignore:
Timestamp:
Jul 15, 2009, 3:54:28 PM (15 years ago)
Author:
waue
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • waue/2009/0715

    v1 v1  
     1{{{
     2                public void map(LongWritable key, Text value,
     3                                OutputCollector<Text, IntWritable> output, Reporter reporter)
     4                                throws IOException {
     5                        String line = (caseSensitive) ? value.toString() : value.toString()
     6                                        .toLowerCase();
     7
     8                        for (String pattern : patternsToSkip) {
     9                                line = line.replaceAll(pattern, "");
     10                        }
     11
     12                        StringTokenizer tokenizer = new StringTokenizer(line);
     13                        while (tokenizer.hasMoreTokens()) {
     14                                word.set(tokenizer.nextToken());
     15                                output.collect(word, one);
     16                                reporter.incrCounter(Counters.INPUT_WORDS, 1);
     17                        }
     18
     19                        if ((++numRecords % 100) == 0) {
     20                                reporter.setStatus("Finished processing " + numRecords
     21                                                + " records " + "from the input file: " + inputFile);
     22                        }
     23                }
     24        }
     25
     26        public static class Reduce extends MapReduceBase implements
     27                        Reducer<Text, IntWritable, Text, IntWritable> {
     28                public void reduce(Text key, Iterator<IntWritable> values,
     29                                OutputCollector<Text, IntWritable> output, Reporter reporter)
     30                                throws IOException {
     31                        int sum = 0;
     32                        while (values.hasNext()) {
     33                                sum += values.next().get();
     34                        }
     35                        output.collect(key, new IntWritable(sum));
     36                }
     37        }
     38}}}