PageRankFn extends AppFunction { @Override public void run(Parameters p, PrintStream output) throws Exception { if (!p.containsKey("linkdata")) { output.println(getHelpString()); return; } if (!p.containsKey("lambda")) { p.set("lambda", 0.5); } assert (p.getDouble("lambda") <= 1.0 && p.getDouble("lambda") >= 0.0); File outputFolder = new File(p.getString("outputFolder")); logger.info("Initializing..."); long docCount = initialize(p, output); if (docCount == 0) { output.println("failed to initialize. Aborting."); return; } p.set("docCount", docCount); int maxItrs = (int) p.get("maxItr", 10); int convergedAt = 0; for (int i = 1; i <= maxItrs; i++) { logger.info("Starting iteration " + i); File itrIn = new File(outputFolder, "pageranks." + (i-1)); File itrOut = new File(outputFolder, "pageranks." + i); if (!itrOut.isDirectory()) { File itrOutTmp = new File(outputFolder, "pageranks." + i + ".tmp"); Job itr = getIterationJob(p, itrIn, itrOutTmp, i); boolean success = runTupleFlowInstance(itr, new File(outputFolder, "pagerank-job-tmp." + i), p, output); if (!success) { logger.warning("PAGERANK FAILED TO EXECUTE."); return; } itrOutTmp.renameTo(itrOut); } convergedAt = i; if (checkConvergence(i, p)) { logger.info("Converged at " + i); break; } } if (convergedAt > maxItrs) { logger.info("MaxIterations reached at " + maxItrs); } logger.info("Finalizing..."); finalize(p, convergedAt, output); logger.info("Finished"); }  @Override String getName(); @Override String getHelpString(); @Override void run(Parameters p, PrintStream output);  }
@Test public void testSomeMethod() throws Exception { File tempDir = FileUtility.createTemporaryDirectory(); try { File input = new File(tempDir, "input.trecweb"); HarvestLinksFnTest.writeInput(input); File galago = new File(tempDir, "galago"); File jobTmp = new File(tempDir, "jobTmp"); Parameters p = Parameters.create(); p.set("inputPath", input.getAbsolutePath()); p.set("indri", false); p.set("galago", true); p.set("outputFolder", galago.getAbsolutePath()); p.set("galagoDist", 3); p.set("distrib", 2); p.set("galagoJobDir", jobTmp.getAbsolutePath()); p.set("server", false); HarvestLinksFn hl = new HarvestLinksFn(); hl.run(p, System.out); File pagerank = new File(tempDir, "pagerank"); File jobTmp2 = new File(tempDir, "jobTmp2"); Parameters p2 = Parameters.create(); p2.set("linkdata", galago.getAbsolutePath()); p2.set("outputFolder", pagerank.getAbsolutePath()); p2.set("lambda", 0.5); p2.set("maxItr", 10); p2.set("server", false); p2.set("distrib", 2); p2.set("galagoJobDir", jobTmp2.getAbsolutePath()); p2.set("server", false); p2.set("delta", 0.000000001); PageRankFn pg = new PageRankFn(); pg.run(p2, System.out); File out1 = new File(pagerank, "pagerank.docNameOrder"); String data = Utility.readFileToString(out1); String exp = "test-0 0.14044514319221924\n" + "test-1 0.10091959505482992\n" + "test-10 0.05115981927289599\n" + "test-11 0.05115981927289599\n" + "test-2 0.08488240356450753\n" + "test-3 0.08673666439408949\n" + "test-4 0.07918772966163073\n" + "test-5 0.0954103007236506\n" + "test-6 0.07937310923332822\n" + "test-7 0.07387799299215828\n" + "test-8 0.07558165579260986\n" + "test-9 0.08126576684518416\n"; checkOutput(data, exp); File out2 = new File(pagerank, "pagerank.scoreOrder"); data = Utility.readFileToString(out2); exp = "test-0 0.14044514319221924\n" + "test-1 0.10091959505482992\n" + "test-5 0.0954103007236506\n" + "test-3 0.08673666439408949\n" + "test-2 0.08488240356450753\n" + "test-9 0.08126576684518416\n" + "test-6 0.07937310923332822\n" + "test-4 0.07918772966163073\n" + "test-8 0.07558165579260986\n" + "test-7 0.07387799299215828\n" + "test-10 0.05115981927289599\n" + "test-11 0.05115981927289599\n"; checkOutput(data, exp); } finally { FSUtil.deleteDirectory(tempDir); } }