-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTweetsMapper.java
More file actions
27 lines (23 loc) · 1.3 KB
/
TweetsMapper.java
File metadata and controls
27 lines (23 loc) · 1.3 KB
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
import java.io.IOException;
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.util.regex.Pattern;
public class TweetsMapper
extends Mapper<LongWritable, Text, Text, IntWritable>{
private static final int MISSING = 9999;
@Override
public void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException{
String str = value.toString();
if (Pattern.compile(Pattern.quote("hackathon"),Pattern.CASE_INSENSITIVE).matcher(str).find()) context.write(new Text("hackathon"), new IntWritable(1));
if (Pattern.compile(Pattern.quote("Dec"),Pattern.CASE_INSENSITIVE).matcher(str).find()) context.write(new Text("Dec"), new IntWritable(1));
if (Pattern.compile(Pattern.quote("Chicago"),Pattern.CASE_INSENSITIVE).matcher(str).find()) context.write(new Text("Chicago"), new IntWritable(1));
if (Pattern.compile(Pattern.quote("Java"),Pattern.CASE_INSENSITIVE).matcher(str).find()) context.write(new Text("Java"), new IntWritable(1));
context.write(new Text("hackathon"), new IntWritable(0));
context.write(new Text("Dec"), new IntWritable(0));
context.write(new Text("Chicago"), new IntWritable(0));
context.write(new Text("Java"), new IntWritable(0));
}
}