comparison src/pagerank/TPReadWikiLink.java @ 14:86567db31710 draft

fix
author one
date Sat, 08 Sep 2012 04:50:50 +0900
parents 0ef7268bbbac
children e1d758d08e9c
comparison
equal deleted inserted replaced
13:0ef7268bbbac 14:86567db31710
23 23
24 public class TPReadWikiLink { 24 public class TPReadWikiLink {
25 25
26 public static void main(String[] args) { 26 public static void main(String[] args) {
27 27
28 // final String fileDB = "./resources/tinkerpopDB"; 28 final String fileDB = "./resources/tinkerpopDB";
29 29
30 final long PAGENUM = 100; 30 final long PAGENUM = 11;
31 final String fileDB = "./resources/tinkerGraph"+Long.toString(PAGENUM); 31 // final String fileDB = "./resources/tinkerGraph"+Long.toString(PAGENUM);
32 final String pageRankLog = "./resources/wikiPageRank"+Long.toString(PAGENUM)+".log"; 32 final String pageRankLog = "./resources/wikiPageRank"+Long.toString(PAGENUM)+".log";
33 33
34 try { 34 try {
35 Graph graph = new TinkerGraph(); 35 Graph graph = new TinkerGraph();
36 FileInputStream in = new FileInputStream(new File(fileDB)); 36 FileInputStream in = new FileInputStream(new File(fileDB));
48 // String nodeIds[] = {"80", "290", "21", "164", "41972", "103700", "65956", "103700"}; 48 // String nodeIds[] = {"80", "290", "21", "164", "41972", "103700", "65956", "103700"};
49 String nodeIds[] = {"146","148"}; 49 String nodeIds[] = {"146","148"};
50 50
51 /* 51 /*
52 long start = java.lang.System.currentTimeMillis(); 52 long start = java.lang.System.currentTimeMillis();
53 writeComputeTransition(ltv, nodeIds, 50, PAGENUM); 53 writeComputeTransition(ltv, nodeIds, 10, PAGENUM);
54 long end = java.lang.System.currentTimeMillis(); 54 long end = java.lang.System.currentTimeMillis();
55 long time = end - start; 55 long time = end - start;
56 System.out.println(time); 56 System.out.println(time);
57 */ 57 */
58 for (int i=0; i<10; i++ ) {
59 long start = java.lang.System.currentTimeMillis();
60 for (int j=0; j<10; j++){
61 for (Vertex v : graph.getVertices()) {
62 ltv.computePageRankUsingPipes(v.getId());
63 }
64 }
65 long end = java.lang.System.currentTimeMillis();
66 long time = end - start;
67 System.out.println(time);
68 }
69
58 70
59 71
60 for (int i=0; i<10; i++) { 72 FileOutputStream fos = new FileOutputStream(new File(pageRankLog));
61 long start = java.lang.System.currentTimeMillis(); 73 descendingOrder(graph, ltv, fos);
62 for (int j=0; j<10; j++){
63 for (Vertex v : graph.getVertices()) {
64 ltv.computePageRankUsingPipes(v.getId());
65 }
66 }
67 long end = java.lang.System.currentTimeMillis();
68 long time = end - start;
69 // System.out.println(time);
70 }
71 /* 74 /*
72 long count = 0;
73 for (Vertex v: graph.getVertices()) {
74 count++;
75 System.out.print("No."+count+" ");
76 System.out.print("title: "+v.getProperty("pageTitle"));
77 System.out.print(" pageRank: "+v.getProperty("pageRank"));
78 System.out.println();
79 System.out.flush();
80 }
81 */
82
83 FileOutputStream fos = new FileOutputStream(new File(pageRankLog));
84 descendingOrder(graph, fos);
85 // descendingOrder(wikiHash, fos);
86
87 FileOutputStream out = new FileOutputStream(new File(fileDB)); 75 FileOutputStream out = new FileOutputStream(new File(fileDB));
88 GraphMLWriter.outputGraph(graph, out); 76 GraphMLWriter.outputGraph(graph, out);
89 out.close(); 77 out.close();
90 78 */
91 // loop(ltv); 79 // loop(ltv);
92 80
93 } catch (NumberFormatException e){ 81 } catch (NumberFormatException e){
94 System.out.println("Program exit"); 82 System.out.println("Program exit");
95 } catch (Exception e) { 83 } catch (Exception e) {
163 } 151 }
164 fos.close(); 152 fos.close();
165 153
166 } 154 }
167 155
168 public static void descendingOrder(Graph graph, FileOutputStream fos) throws IOException { 156 public static void descendingOrder(Graph graph, LinkToVertex ltv, FileOutputStream fos) throws IOException {
169 ArrayList<WikiPage> list = new ArrayList<WikiPage>(); 157 ArrayList<WikiPage> list = new ArrayList<WikiPage>();
170 for (Vertex v : graph.getVertices()) { 158 for (Vertex v : graph.getVertices()) {
171 WikiPage w = new WikiPage(v); 159 WikiPage w = new WikiPage(v);
160 w.setInHasLink(ltv.computeInHasLink(v));
161 w.setOutHasLink(ltv.computeOutHasLink(v));
172 list.add(w); 162 list.add(w);
173 } 163 }
174 Collections.sort(list, new Comparator<WikiPage>(){ 164 Collections.sort(list, new Comparator<WikiPage>(){
175 public int compare(WikiPage w1, WikiPage w2) { 165 public int compare(WikiPage w1, WikiPage w2) {
176 return (int)(w2.getRank()*Math.pow(10, 5)) - (int)(w1.getRank()*Math.pow(10, 5)); 166 return (int)(w2.getRank()*Math.pow(10, 5)) - (int)(w1.getRank()*Math.pow(10, 5));