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 29 30 31 32 33 34 35 36 37 38 39 40
| package com.matrix.InverseIndex;
import java.io.IOException;
import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Reducer;
public class InverseIndexCombine extends Reducer<Text, Text, Text, Text> {
private Text info = new Text();
@Override protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException { int sum = 0;
for (Text value : values) { System.out.println("combine:" + value.toString()); sum += Integer.parseInt(value.toString());
int splitIndex = key.toString().indexOf(":"); System.out.println("combine splitIndex:" + splitIndex);
System.out.println("combine splitIndex :" + key.toString().substring(splitIndex + 1));
info.set(key.toString().substring(splitIndex + 1) + ":" + sum);
System.out.println("combine 单词 :" + key.toString().substring(0, splitIndex)); key.set(key.toString().substring(0, splitIndex));
context.write(key, info); }
} }
|