【转】PageRank算法源代码实现(java)
package pagerank;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Hashtable;
public class PageRank {
public static void main(String[] args) throws Exception {
String[] linesarr;
Hashtable<String, Integer> docIDandNum = new Hashtable<String, Integer>();
int total = 0;
int father, son;
int outdegree = 0;
// 读取文件,得到docid,计算链接总数total,outdegree在迭代的时候计算
File linkfile = new File(\
BufferedReader linkinput = new BufferedReader(new FileReader(linkfile));
String line = linkinput.readLine();
while (line != null) {
++total;
linesarr = line.split(\
if (linesarr.length > 0) {
// outdegree = linesarr.length - 1;
// for(int j = 1; j <= linesarr.length - 1; ++j) {
// if(linesarr[j].equals(linesarr[0]))
// outdegree--;
// }
if (linesarr[0] != null) {
docIDandNum.put(linesarr[0], total);
// System.out.println(\链接\linesarr[0] + \的出度为\
}
}
linesarr = null;
line = linkinput.readLine();
}
linkinput.close();
// System.out.println(\链接总数为:\
if (total > 0) {
// pageRank[]存放PR值
float[] pageRank = new float[total + 1];
// 链入页面的计算总和
float[] prTmp = new float[total + 1];
// 设置pageRank[]初始值为1.0f