forked from bicCluster/learning-cluster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWCMapper.java
More file actions
23 lines (19 loc) · 783 Bytes
/
WCMapper.java
File metadata and controls
23 lines (19 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import java.io.IOException;
import java.util.StringTokenizer;
/**
* Created by yifeiliu on 2/4/17.
*/
public class WCMapper extends Mapper<Object, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
StringTokenizer tokenizer = new StringTokenizer(value.toString());
while(tokenizer.hasMoreTokens()) {
word.set(tokenizer.nextToken().replaceAll("[^a-zA-Z0-9]+", "")); //remove special characters
context.write(word, one);
}
}
}