Mercurial > hg > Members > nobuyasu > TestNeo4j
view src/wikigraph/ReadWikiLink.java @ 27:4c0b10bb5192 draft default tip
print ./resource/wikiPageRank.log
author | one |
---|---|
date | Mon, 03 Sep 2012 16:25:28 +0900 |
parents | cfbab7d87188 |
children |
line wrap: on
line source
package wikigraph; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedList; import java.util.Map; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Path; import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.traversal.Traverser; import org.neo4j.kernel.EmbeddedGraphDatabase; import org.neo4j.tooling.GlobalGraphOperations; import wikigraph.LinkToNode.RelTypes; public class ReadWikiLink { public static void main(String[] args) { GraphDatabaseService graphDb = new EmbeddedGraphDatabase("wikiLinkDB"); GlobalGraphOperations graphOpe = GlobalGraphOperations.at(graphDb); LinkToNode ltn = new LinkToNode(graphDb, graphOpe); Transaction tx = graphDb.beginTx(); try { // ltn.initAllNodePageRank(); final long AllNodeNumber = ltn.searchAllNodes(); HashMap<String, WikiPage> wikiHash = ltn.getWikiPageHash(); WikiPage maxW = new WikiPage(); ArrayList<WikiPage> list = new ArrayList<WikiPage>(); for (String title : wikiHash.keySet()) { WikiPage w = wikiHash.get(title); list.add(w); if (maxW.getRank() < w.getRank() ) { maxW = w; } } Collections.sort(list, new Comparator<WikiPage>(){ public int compare(WikiPage w1, WikiPage w2) { return (int)(w2.getRank()*Math.pow(10, 6)) - (int)(w1.getRank()*Math.pow(10,6)); } }); FileOutputStream fos = new FileOutputStream("./resource/wikiPageRank.log"); for (WikiPage w : list) { w.printInfo(fos); } fos.close(); System.out.println("\nMax Page Rank"); maxW.printInfo(); /* final int NODEID = 119392; Node n = graphDb.getNodeById(NODEID); n.setProperty(LinkToNode.PAGE_RANK,(double)0.0); ltn.computePageRank(n); ltn.printNodeInfo(NODEID); /* final int nodeIds[] = {2892, 2850, 1574, 518, 3618}; LinkedList<FileOutputStream> fosList = new LinkedList<FileOutputStream>(); for (int i: nodeIds) { String filename = String.format("./resource/NodeId_%d.dat", i); FileOutputStream fos = new FileOutputStream(filename); fos.write( String.format("# Node ID %d\n",i).getBytes()); fosList.add(fos); } for (int i=0; i<50; i++) { for (Node node : graphOpe.getAllNodes()) { ltn.computePageRank(node); } for (int index=0; index<nodeIds.length; index++){ FileOutputStream fos = fosList.get(index); printPageRankLog(fos, ltn, nodeIds[index], i); } } for (FileOutputStream fos: fosList) { fos.close(); } */ } catch (Exception e) { e.printStackTrace(); } finally { tx.success(); tx.finish(); graphDb.shutdown(); } } public static void printPageRankLog(FileOutputStream fos, int x, double rank) throws IOException { fos.write( (x+" "+ rank+"\n").getBytes() ); fos.flush(); } public static void printPageRankLog(FileOutputStream fos, LinkToNode ltn, int nodeId, int x) throws IOException { double rank = ltn.getPageRank(ltn.getNode(nodeId)); fos.write( (x+" "+ rank+"\n").getBytes() ); fos.flush(); } }