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

create descendiangOrder(Graph,FileOutputStream) method.
author one
date Sat, 08 Sep 2012 04:12:19 +0900
parents 8e3bb1843beb
children 86567db31710
line wrap: on
line diff
--- a/src/pagerank/TPReadWikiLink.java	Thu Sep 06 06:05:24 2012 +0900
+++ b/src/pagerank/TPReadWikiLink.java	Sat Sep 08 04:12:19 2012 +0900
@@ -25,8 +25,11 @@
 
 	public static void main(String[] args) {
 
-		final String fileDB = "./resources/tinkerpopDB";
-		
+//		final String fileDB = "./resources/tinkerpopDB";
+
+		final long PAGENUM = 100; 
+		final String fileDB = "./resources/tinkerGraph"+Long.toString(PAGENUM);	
+		final String pageRankLog = "./resources/wikiPageRank"+Long.toString(PAGENUM)+".log";	
 		
 		try {
 			Graph graph = new TinkerGraph();
@@ -35,28 +38,55 @@
 			in.close();
 			LinkToVertex ltv = new LinkToVertex(graph);
 
-//			ltv.initPageRankAllVertex();
-/*
+			ltv.initPageRankAllVertex();
+
 			final long AllVertexNumber = ltv.searchAllVertices();
 			HashMap<String, WikiPage> wikiHash = ltv.getWikiPageHash();
 			System.out.println("AllVertexNumber = "+AllVertexNumber);
-*/
+
+
+//			String nodeIds[] = {"80", "290", "21", "164", "41972", "103700", "65956", "103700"};
+			String nodeIds[] = {"146","148"};
+			
 /*
-			String nodeIds[] = {"80", "290", "21", "164"};
-			writeComputeTransition(ltv, nodeIds, 50);
+			long start = java.lang.System.currentTimeMillis();
+			writeComputeTransition(ltv, nodeIds, 50, PAGENUM);
+			long end = java.lang.System.currentTimeMillis();
+			long time = end - start;
+			System.out.println(time);
+*/
+			
 
-*/
-/*
-			FileOutputStream fos = new FileOutputStream(new File("./resources/wikiPageRank.log"));
-			descendingOrder(wikiHash, fos);			
+			for (int i=0; i<10; i++) {
+				long start = java.lang.System.currentTimeMillis();
+				for (int j=0; j<10; j++){
+					for (Vertex v : graph.getVertices()) {
+						ltv.computePageRankUsingPipes(v.getId());
+					}
+				}
+				long end = java.lang.System.currentTimeMillis();
+				long time = end - start;
+//				System.out.println(time);
+			}
+/*			
+			long count = 0;
+			for (Vertex v: graph.getVertices()) {
+				count++;
+				System.out.print("No."+count+" ");
+				System.out.print("title: "+v.getProperty("pageTitle"));
+				System.out.print(" pageRank: "+v.getProperty("pageRank"));
+				System.out.println();
+				System.out.flush();
+			}
 */
 
-			
+			FileOutputStream fos = new FileOutputStream(new File(pageRankLog));
+			descendingOrder(graph, fos);			
+			//			descendingOrder(wikiHash, fos);			
 			
 			FileOutputStream out = new FileOutputStream(new File(fileDB));
 			GraphMLWriter.outputGraph(graph, out);
 			out.close();
-
 			
 //			loop(ltv);
 			
@@ -83,21 +113,22 @@
 		}
 	}
 
-	public static void writeComputeTransition(LinkToVertex ltv,final String nodeIds[], int count) throws IOException {
+	public static void writeComputeTransition(LinkToVertex ltv,final String nodeIds[], int count, long pagenum) throws IOException {
 		LinkedList<FileOutputStream> fosList = new LinkedList<FileOutputStream>();
 		for (String id: nodeIds) {
-			String filename = "./resources/NodeId_"+id+".dat";
+			String filename = "./resources/VertexId_"+id+"_num"+Long.toString(pagenum)+".dat";
 			FileOutputStream fos = null;
 			fos = new FileOutputStream(filename);
 
 			Vertex v = ltv.getVertexById(id);
-			fos.write( ("# Node ID "+id+" "+ ltv.getPageTitle(v)+"\n").getBytes());
+			fos.write( ("# Vertex ID "+id+" "+ ltv.getPageTitle(v)+"\n").getBytes());
 			fosList.add(fos);
 		}
 		
 		for (int i=0; i<count; i++) {
 			for (Vertex v : ltv.getAllVertices() ) {
-				ltv.computePageRank(v);
+//				ltv.computePageRank(v);
+				ltv.computePageRankUsingPipes(v.getId());
 			}
 
 			for (int index=0; index<nodeIds.length; index++){
@@ -120,12 +151,37 @@
 		}
 		Collections.sort(list, new Comparator<WikiPage>(){
 				public int compare(WikiPage w1, WikiPage w2) {
-				return (int)(w2.getRank()*Math.pow(10, 10)) - (int)(w1.getRank()*Math.pow(10,10));
+				return (int)(w2.getRank()*Math.pow(10, 5)) - (int)(w1.getRank()*Math.pow(10, 5));
 				}
 		});
 		
+		long count = 1;
 		for (WikiPage w : list) {
+			fos.write(("No."+count+"\n").getBytes());
 			w.printInfo(fos);
+			count++;
+		}
+		fos.close();
+		
+	}
+
+	public static void descendingOrder(Graph graph, FileOutputStream fos) throws IOException {
+		ArrayList<WikiPage> list = new ArrayList<WikiPage>();
+		for (Vertex v : graph.getVertices()) {
+			WikiPage w = new WikiPage(v);
+			list.add(w);
+		}
+		Collections.sort(list, new Comparator<WikiPage>(){
+				public int compare(WikiPage w1, WikiPage w2) {
+				return (int)(w2.getRank()*Math.pow(10, 5)) - (int)(w1.getRank()*Math.pow(10, 5));
+				}
+		});
+		
+		long count = 1;
+		for (WikiPage w : list) {
+			fos.write(("No."+count+"\n").getBytes());
+			w.printInfo(fos);
+			count++;
 		}
 		fos.close();