import org apache hadoop io IntWritable import org apache hadoop io Lo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import java.io.IOException;
public class WordMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
@Override
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String line = value.toString();
String[] words = line.replaceAll("(?U)[^\\w\\s]", "").toLowerCase().split("\\s+");
for (String word: words) {
context.write(new Text(word), new IntWritable(1));
}
}
}