obar1
6/11/2015 - 2:48 PM

PatentMapper_PatentReducer

import java.io.IOException;

import org.apache.hadoop.io.*;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;


public class PatentMapper extends Mapper<LongWritable, Text, Text, IntWritable> {

	public void map(LongWritable ikey, Text ivalue, Context context)
			throws IOException, InterruptedException {

		String txt = ivalue.toString();
		String[] parts = txt.split(" ");
		context.write(new Text(parts[0].toLowerCase()), new IntWritable(1));
	}

}

import java.io.IOException;

import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.Reducer;


public class PatentReducer extends Reducer<Text, IntWritable, Text, IntWritable> {

	public void reduce(Text _key, Iterable<IntWritable> values, Context context)
			throws IOException, InterruptedException {
		int sum =0;
		// process values
		for (IntWritable val : values) {
sum+= val.get();
		}
		context.write(_key, new IntWritable(sum));
	}

}