Mercurial > hg > Members > nobuyasu > TPPageRank
comparison 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 |
comparison
equal
deleted
inserted
replaced
12:7e38484474f4 | 13:0ef7268bbbac |
---|---|
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; | |
31 final String fileDB = "./resources/tinkerGraph"+Long.toString(PAGENUM); | |
32 final String pageRankLog = "./resources/wikiPageRank"+Long.toString(PAGENUM)+".log"; | |
30 | 33 |
31 try { | 34 try { |
32 Graph graph = new TinkerGraph(); | 35 Graph graph = new TinkerGraph(); |
33 FileInputStream in = new FileInputStream(new File(fileDB)); | 36 FileInputStream in = new FileInputStream(new File(fileDB)); |
34 GraphMLReader.inputGraph(graph, in); | 37 GraphMLReader.inputGraph(graph, in); |
35 in.close(); | 38 in.close(); |
36 LinkToVertex ltv = new LinkToVertex(graph); | 39 LinkToVertex ltv = new LinkToVertex(graph); |
37 | 40 |
38 // ltv.initPageRankAllVertex(); | 41 ltv.initPageRankAllVertex(); |
39 /* | 42 |
40 final long AllVertexNumber = ltv.searchAllVertices(); | 43 final long AllVertexNumber = ltv.searchAllVertices(); |
41 HashMap<String, WikiPage> wikiHash = ltv.getWikiPageHash(); | 44 HashMap<String, WikiPage> wikiHash = ltv.getWikiPageHash(); |
42 System.out.println("AllVertexNumber = "+AllVertexNumber); | 45 System.out.println("AllVertexNumber = "+AllVertexNumber); |
46 | |
47 | |
48 // String nodeIds[] = {"80", "290", "21", "164", "41972", "103700", "65956", "103700"}; | |
49 String nodeIds[] = {"146","148"}; | |
50 | |
51 /* | |
52 long start = java.lang.System.currentTimeMillis(); | |
53 writeComputeTransition(ltv, nodeIds, 50, PAGENUM); | |
54 long end = java.lang.System.currentTimeMillis(); | |
55 long time = end - start; | |
56 System.out.println(time); | |
43 */ | 57 */ |
44 /* | 58 |
45 String nodeIds[] = {"80", "290", "21", "164"}; | 59 |
46 writeComputeTransition(ltv, nodeIds, 50); | 60 for (int i=0; i<10; i++) { |
47 | 61 long start = java.lang.System.currentTimeMillis(); |
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 /* | |
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 } | |
48 */ | 81 */ |
49 /* | 82 |
50 FileOutputStream fos = new FileOutputStream(new File("./resources/wikiPageRank.log")); | 83 FileOutputStream fos = new FileOutputStream(new File(pageRankLog)); |
51 descendingOrder(wikiHash, fos); | 84 descendingOrder(graph, fos); |
52 */ | 85 // descendingOrder(wikiHash, fos); |
53 | |
54 | |
55 | 86 |
56 FileOutputStream out = new FileOutputStream(new File(fileDB)); | 87 FileOutputStream out = new FileOutputStream(new File(fileDB)); |
57 GraphMLWriter.outputGraph(graph, out); | 88 GraphMLWriter.outputGraph(graph, out); |
58 out.close(); | 89 out.close(); |
59 | |
60 | 90 |
61 // loop(ltv); | 91 // loop(ltv); |
62 | 92 |
63 } catch (NumberFormatException e){ | 93 } catch (NumberFormatException e){ |
64 System.out.println("Program exit"); | 94 System.out.println("Program exit"); |
81 System.out.print("\nPlease enter Node Id...>"); | 111 System.out.print("\nPlease enter Node Id...>"); |
82 System.out.flush(); | 112 System.out.flush(); |
83 } | 113 } |
84 } | 114 } |
85 | 115 |
86 public static void writeComputeTransition(LinkToVertex ltv,final String nodeIds[], int count) throws IOException { | 116 public static void writeComputeTransition(LinkToVertex ltv,final String nodeIds[], int count, long pagenum) throws IOException { |
87 LinkedList<FileOutputStream> fosList = new LinkedList<FileOutputStream>(); | 117 LinkedList<FileOutputStream> fosList = new LinkedList<FileOutputStream>(); |
88 for (String id: nodeIds) { | 118 for (String id: nodeIds) { |
89 String filename = "./resources/NodeId_"+id+".dat"; | 119 String filename = "./resources/VertexId_"+id+"_num"+Long.toString(pagenum)+".dat"; |
90 FileOutputStream fos = null; | 120 FileOutputStream fos = null; |
91 fos = new FileOutputStream(filename); | 121 fos = new FileOutputStream(filename); |
92 | 122 |
93 Vertex v = ltv.getVertexById(id); | 123 Vertex v = ltv.getVertexById(id); |
94 fos.write( ("# Node ID "+id+" "+ ltv.getPageTitle(v)+"\n").getBytes()); | 124 fos.write( ("# Vertex ID "+id+" "+ ltv.getPageTitle(v)+"\n").getBytes()); |
95 fosList.add(fos); | 125 fosList.add(fos); |
96 } | 126 } |
97 | 127 |
98 for (int i=0; i<count; i++) { | 128 for (int i=0; i<count; i++) { |
99 for (Vertex v : ltv.getAllVertices() ) { | 129 for (Vertex v : ltv.getAllVertices() ) { |
100 ltv.computePageRank(v); | 130 // ltv.computePageRank(v); |
131 ltv.computePageRankUsingPipes(v.getId()); | |
101 } | 132 } |
102 | 133 |
103 for (int index=0; index<nodeIds.length; index++){ | 134 for (int index=0; index<nodeIds.length; index++){ |
104 FileOutputStream fos = fosList.get(index); | 135 FileOutputStream fos = fosList.get(index); |
105 printPageRankLog(fos, ltv, nodeIds[index], i); | 136 printPageRankLog(fos, ltv, nodeIds[index], i); |
118 WikiPage w = wikiHash.get(title); | 149 WikiPage w = wikiHash.get(title); |
119 list.add(w); | 150 list.add(w); |
120 } | 151 } |
121 Collections.sort(list, new Comparator<WikiPage>(){ | 152 Collections.sort(list, new Comparator<WikiPage>(){ |
122 public int compare(WikiPage w1, WikiPage w2) { | 153 public int compare(WikiPage w1, WikiPage w2) { |
123 return (int)(w2.getRank()*Math.pow(10, 10)) - (int)(w1.getRank()*Math.pow(10,10)); | 154 return (int)(w2.getRank()*Math.pow(10, 5)) - (int)(w1.getRank()*Math.pow(10, 5)); |
124 } | 155 } |
125 }); | 156 }); |
126 | 157 |
158 long count = 1; | |
127 for (WikiPage w : list) { | 159 for (WikiPage w : list) { |
160 fos.write(("No."+count+"\n").getBytes()); | |
128 w.printInfo(fos); | 161 w.printInfo(fos); |
162 count++; | |
163 } | |
164 fos.close(); | |
165 | |
166 } | |
167 | |
168 public static void descendingOrder(Graph graph, FileOutputStream fos) throws IOException { | |
169 ArrayList<WikiPage> list = new ArrayList<WikiPage>(); | |
170 for (Vertex v : graph.getVertices()) { | |
171 WikiPage w = new WikiPage(v); | |
172 list.add(w); | |
173 } | |
174 Collections.sort(list, new Comparator<WikiPage>(){ | |
175 public int compare(WikiPage w1, WikiPage w2) { | |
176 return (int)(w2.getRank()*Math.pow(10, 5)) - (int)(w1.getRank()*Math.pow(10, 5)); | |
177 } | |
178 }); | |
179 | |
180 long count = 1; | |
181 for (WikiPage w : list) { | |
182 fos.write(("No."+count+"\n").getBytes()); | |
183 w.printInfo(fos); | |
184 count++; | |
129 } | 185 } |
130 fos.close(); | 186 fos.close(); |
131 | 187 |
132 } | 188 } |
133 | 189 |