# HG changeset patch # User one # Date 1346830487 -32400 # Node ID c7b139ff27e2022361f38d7efb2da352bbda66bc # Parent 8ea2212eaee038579c261d19035d91aa1db67af1 compute PageRank. initial value is 1/ AllVertexNumber diff -r 8ea2212eaee0 -r c7b139ff27e2 src/pagerank/LinkConvertGraph.java --- a/src/pagerank/LinkConvertGraph.java Wed Sep 05 15:39:26 2012 +0900 +++ b/src/pagerank/LinkConvertGraph.java Wed Sep 05 16:34:47 2012 +0900 @@ -90,8 +90,8 @@ public static void main(String[] args) { - final String filename = "./resources/article.xml"; -// final String filename = "/Users/aotokage/testProgram/wiki/ja-pages_current.xml"; +// final String filename = "./resources/article.xml"; + final String filename = "/Users/aotokage/testProgram/wiki/ja-pages_current.xml"; LinkConvertGraph lcg; diff -r 8ea2212eaee0 -r c7b139ff27e2 src/pagerank/LinkToVertex.java --- a/src/pagerank/LinkToVertex.java Wed Sep 05 15:39:26 2012 +0900 +++ b/src/pagerank/LinkToVertex.java Wed Sep 05 16:34:47 2012 +0900 @@ -14,8 +14,12 @@ Graph graph; public final static String PAGE_TITLE = "pageTitle"; public final static String PAGE_RANK = "pageRank"; + // pageIdTable + // key: pageTitle value: Vertex ID private HashMap pageIdTable = new HashMap(); + // wikiPageHash + // key: pageTitle value: wikiPage(class) private HashMap wikiPageHash = new HashMap(); private long AllVertexNumber; @@ -86,8 +90,8 @@ return graph.getVertex(id); } - Vertex getNode(String nodeId) { - return graph.getVertex(nodeId); + Vertex getVertexById(String id) { + return graph.getVertex(id); } Edge setRelationship(Vertex v1, Vertex v2, String label) { @@ -201,23 +205,23 @@ } public double computePageRank(Vertex v) { - double sum = 0; - double pageRank = 0; + double sum = 0.0; + double pageRank = 0.0; String title = getPageTitle(v); WikiPage wiki = wikiPageHash.get(title); for (Edge edge : v.getEdges(Direction.IN, HAS_LINK) ) { Vertex linkV = edge.getVertex(Direction.OUT); - sum += (double) ((Double) linkV.getProperty(PAGE_RANK)) / computeInHasLink(linkV) ; + if (computeInHasLink(linkV) == 0) { + sum += (Double) linkV.getProperty(PAGE_RANK); + } else { + sum += ((Double) linkV.getProperty(PAGE_RANK)) / computeInHasLink(linkV) ; + } } - - if (computeOutHasLink(v) == 0) { - pageRank = (double) sum * weight1 - + (double) ((double) 1 / AllVertexNumber * weight2); - } else { - pageRank = (double) ((double)sum / computeOutHasLink(v) * weight1) - + (double) ((double) 1 / AllVertexNumber * weight2); - } + + pageRank = (double) sum * weight1 + + (double) ((double) 1 / AllVertexNumber * weight2); + wiki.setRank(pageRank); v.setProperty(PAGE_RANK, pageRank); return pageRank; diff -r 8ea2212eaee0 -r c7b139ff27e2 src/pagerank/TPReadWikiLink.java --- a/src/pagerank/TPReadWikiLink.java Wed Sep 05 15:39:26 2012 +0900 +++ b/src/pagerank/TPReadWikiLink.java Wed Sep 05 16:34:47 2012 +0900 @@ -34,24 +34,23 @@ GraphMLReader.inputGraph(graph, in); in.close(); LinkToVertex ltv = new LinkToVertex(graph); - + final long AllVertexNumber = ltv.searchAllVertices(); HashMap wikiHash = ltv.getWikiPageHash(); System.out.println("AllVertexNumber = "+AllVertexNumber); + + String nodeIds[] = {"1574", "2829", "2850", "3618"}; + writeComputeTransition(ltv, nodeIds, 50); + +// FileOutputStream fos = new FileOutputStream(new File("./resources/wikiPageRank.log")); +// descendingOrder(wikiHash, fos); - for (Vertex v : graph.getVertices() ) { - String id = (String) v.getId(); - System.out.println("id:"+id+" title:"+v.getProperty("pageTitle")+" rank:"+v.getProperty("pageRank")); - } -/* - String nodeIds[] = {"1574", "2829", "2850", "3618"}; - writeComputeTransition(ltv, nodeIds, 30); - + FileOutputStream out = new FileOutputStream(new File(fileDB)); GraphMLWriter.outputGraph(graph, out); out.close(); -*/ + // loop(ltv); @@ -80,13 +79,13 @@ public static void writeComputeTransition(LinkToVertex ltv,final String nodeIds[], int count) throws IOException { LinkedList fosList = new LinkedList(); - for (String i: nodeIds) { - String filename = "./resources/NodeId_"+i+".dat"; + for (String id: nodeIds) { + String filename = "./resources/NodeId_"+id+".dat"; FileOutputStream fos = null; fos = new FileOutputStream(filename); - Vertex v = ltv.getVertex(i); - fos.write( ("# Node ID "+i+" "+ (String)ltv.getPageTitle(v)).getBytes()); + Vertex v = ltv.getVertexById(id); + fos.write( ("# Node ID "+id+" "+ ltv.getPageTitle(v)+"\n").getBytes()); fosList.add(fos); } @@ -131,8 +130,8 @@ fos.flush(); } - public static void printPageRankLog(FileOutputStream fos, LinkToVertex ltv, String nodeId, int x) throws IOException { - double rank = ltv.getPageRank(ltv.getNode(nodeId)); + public static void printPageRankLog(FileOutputStream fos, LinkToVertex ltv, String id, int x) throws IOException { + double rank = ltv.getPageRank(ltv.getVertexById(id)); fos.write( (x+" "+ rank+"\n").getBytes() ); fos.flush(); }