-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIterMapper.java
More file actions
38 lines (25 loc) · 1.11 KB
/
Copy pathIterMapper.java
File metadata and controls
38 lines (25 loc) · 1.11 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
28
29
30
31
32
33
34
35
36
37
38
package edu.upenn.nets212.hw3;
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;
public class IterMapper extends Mapper<LongWritable, Text, Text, Text> {
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String[] line = value.toString().split("\t");
String[] userInfo = line[1].split("!");
if (userInfo.length < 2) { // user has no friends
return;
}
String[] follows = userInfo[1].split(","); //split up the followers
double rank = Double.parseDouble(userInfo[0]);
double numFollows = follows.length;
double weight = rank / numFollows; //determine weight
Text weightToAdd = new Text("" + weight);
for (int i = 0; i < follows.length; i++) {
Text userWeightAdd = new Text(follows[i]);
context.write(userWeightAdd, weightToAdd); //emit the user to add weight and the weight
}
context.write(new Text(line[0]), new Text("!" + userInfo[1])); //adjacency list to preserve into
}
}