diff src/pagerank/LinkToVertex.java @ 13:0ef7268bbbac draft

create descendiangOrder(Graph,FileOutputStream) method.
author one
date Sat, 08 Sep 2012 04:12:19 +0900
parents 9787663edb54
children 86567db31710
line wrap: on
line diff
--- a/src/pagerank/LinkToVertex.java	Thu Sep 06 06:05:24 2012 +0900
+++ b/src/pagerank/LinkToVertex.java	Sat Sep 08 04:12:19 2012 +0900
@@ -6,6 +6,8 @@
 import com.tinkerpop.blueprints.Edge;
 import com.tinkerpop.blueprints.Graph;
 import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.gremlin.java.GremlinPipeline;
+import com.tinkerpop.pipes.util.iterators.SingleIterator;
 
 import pagerank.WikiPage;
 
@@ -14,12 +16,15 @@
 	Graph graph;
 	public final static String PAGE_TITLE = "pageTitle";
 	public final static String PAGE_RANK = "pageRank";
-	// pageIdTable
-	// key: pageTitle value: Vertex ID
+
+	/* pageIdTable
+	 * key: pageTitle value: Vertex ID
+	 */
 	private HashMap<String, Object> pageIdTable = new HashMap<String, Object>();
 
-	// wikiPageHash 
-	// key: pageTitle  value: wikiPage(class)
+	/* wikiPageHash 
+	 * key: pageTitle  value: wikiPage(class)
+	 */
 	private HashMap<String, WikiPage> wikiPageHash = new HashMap<String, WikiPage>();
 	private long AllVertexNumber;
 
@@ -108,7 +113,7 @@
 		}
 	}
 	
-	long searchAllVertices() {
+	public long searchAllVertices() {
 		AllVertexNumber = 0;
 		for (Vertex v : graph.getVertices()) {
 			if ( (v.getProperty(PAGE_TITLE) != null) && 
@@ -221,15 +226,35 @@
 			double pr = (Double)linkV.getProperty(PAGE_RANK);
 			sum += (double) pr / computeOutHasLink(linkV) ;
 		}
-		double tmp = (double) 1 - weight;
-		pageRank = (double) tmp / AllVertexNumber
-				+ (double) sum * weight;
+		pageRank = (double) 1 - weight + (double) sum * weight;
 
 		wiki.setRank(pageRank);
 		v.setProperty(PAGE_RANK, pageRank);
 		return pageRank;
 	}
 	
+	public double computePageRankUsingPipes(Object id) {
+		double sum = 0.0;
+		double pageRank = 0.0;
+		Vertex v = graph.getVertex(id);
+		WikiPage wiki = wikiPageHash.get(v.getProperty(PAGE_TITLE));
+		
+		GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>();
+		pipe.start(graph.getVertex(id)).in("HasLink");
+		for (Vertex inVer : pipe) {
+			Object inVerId = inVer.getId();
+			GremlinPipeline<Vertex,Vertex> inPipe = new GremlinPipeline<Vertex,Vertex>();
+			inPipe.start(graph.getVertex(inVerId)).out("HasLink");
+			long linkNum = inPipe.count();
+			double pr = (Double) inVer.getProperty(PAGE_RANK);
+			sum += 	(double) pr / linkNum;
+		}
+		pageRank = (double) 1 - weight + (double) sum * weight;		
+		wiki.setRank(pageRank);
+		v.setProperty(PAGE_RANK, pageRank);
+		return pageRank;
+	}
+	
 	public void printVertexInfo(int nodeId) {
 		Vertex v = graph.getVertex(nodeId);
 		printInHasLink(v, 1);