-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPageRankMapper.java
46 lines (28 loc) · 1.06 KB
/
PageRankMapper.java
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
39
40
41
42
43
44
45
46
package bigdata;
import java.io.IOException;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.ObjectWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
public class PageRankMapper extends Mapper<LongWritable, Text, Text,ObjectWritable> {
@Override
public void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
try
{
PageRank pageRank=new PageRank(value);
context.write(new Text(pageRank.getNode()), new ObjectWritable( pageRank));
context.getCounter(PageRankDriver.Counter.totalNodes).increment(1);
double pageRankValue= pageRank.getPageRankValue();
double pageRankValueGivenToEachLink = pageRankValue/pageRank.getLinks().size();
for (int i=0; i< pageRank.getLinks().size(); i++)
{
context.write(new Text(pageRank.getLinks().get(i)), new ObjectWritable(new DoubleWritable(pageRankValueGivenToEachLink)));
}
}
catch (Exception e)
{
}
}
}