public class PageRankTests extends PigTests
{
@Test
public void pigPageRankTest() throws Exception
{
PigTest test = createPigTest("datafu/linkanalysis/pageRankTest.pig");
String[] edges = PageRankTest.getWikiExampleEdges();
Map<String,Integer> nodeIds = new HashMap<String,Integer>();
Map<Integer,String> nodeIdsReversed = new HashMap<Integer,String>();
Map<String,Float> expectedRanks = PageRankTest.parseExpectedRanks(PageRankTest.getWikiExampleExpectedRanks());
File f = new File(System.getProperty("user.dir"), "input").getAbsoluteFile();
if (f.exists())
{
f.delete();
}
FileWriter writer = new FileWriter(f);
BufferedWriter bufferedWriter = new BufferedWriter(writer);
for (String edge : edges)
{
String[] edgeParts = edge.split(" ");
String source = edgeParts[0];
String dest = edgeParts[1];
if (!nodeIds.containsKey(source))
{
int id = nodeIds.size();
nodeIds.put(source,id);
nodeIdsReversed.put(id, source);
}
if (!nodeIds.containsKey(dest))
{
int id = nodeIds.size();
nodeIds.put(dest,id);
nodeIdsReversed.put(id, dest);
}
Integer sourceId = nodeIds.get(source);
Integer destId = nodeIds.get(dest);
StringBuffer sb = new StringBuffer();
sb.append("1\t"); // topic
sb.append(sourceId.toString() + "\t");
sb.append(destId.toString() + "\t");
sb.append("1.0\n"); // weight
bufferedWriter.write(sb.toString());
}
bufferedWriter.close();
test.runScript();
Iterator<Tuple> tuples = test.getAlias("data_grouped3");
System.out.println("Final node ranks:");
int nodeCount = 0;
while (tuples.hasNext())
{