Mercurial > hg > Members > nobuyasu > TestNeo4j
diff src/wikigraph/ReadWikiLink.java @ 23:21902773e530 draft
fix ReadWikiLink.java
author | one |
---|---|
date | Tue, 28 Aug 2012 14:38:13 +0900 |
parents | f9ef906676eb |
children | 71fe482aaf32 |
line wrap: on
line diff
--- a/src/wikigraph/ReadWikiLink.java Tue Aug 28 14:04:46 2012 +0900 +++ b/src/wikigraph/ReadWikiLink.java Tue Aug 28 14:38:13 2012 +0900 @@ -16,68 +16,76 @@ public class ReadWikiLink { - public static void main(String[] args) { - GraphDatabaseService graphDb = new EmbeddedGraphDatabase("wikiLinkDB"); - GlobalGraphOperations graphOpe = GlobalGraphOperations.at(graphDb); + GlobalGraphOperations graphOpe = GlobalGraphOperations.at(graphDb); LinkToNode ltn = new LinkToNode(graphDb, graphOpe); - Transaction tx = graphDb. beginTx(); + Transaction tx = graphDb.beginTx(); try { - - final long AllNodeNumber = ltn.searchPageTitleAllNodes(); - - // Key: page_title value: Node ID - HashMap<String,Long> pageIdHash = ltn.getPageIdTable(); - HashMap<String,Long> pageRankHash = ltn.getPageRankTable(); - - long maxRelCount = 0; - String tmpKey=""; - // relHash record number of relationships of each node. - // Key: page_title value: number of relationships - HashMap<String,Long> relHash = new HashMap<String,Long>(); - - // relKeyHash - // key: number of relationships value: ID - HashMap<Long,Long> relKeyHash = new HashMap<Long,Long>(); - - for (String key : pageIdHash.keySet()) { - long id = pageIdHash.get(key); - Node node = graphDb.getNodeById(id); + +// final long AllNodeNumber = ltn.searchPageTitleAllNodes(); + final long AllNodeNumber = ltn.searchAllNodes(); + + long maxRelCount = 0; + String tmpKey = ""; + // relHash record number of relationships of each node. + // Key: page_title value: number of relationships + HashMap<String, Long> relHash = new HashMap<String, Long>(); + + // relKeyHash + // key: number of relationships value: ID + HashMap<Long, Long> relKeyHash = new HashMap<Long, Long>(); + + HashMap<String,WikiPage> wikiHash = ltn.getWikiPageHash(); + + for (String title: wikiHash.keySet()) { + WikiPage w = wikiHash.get(title); + long id = w.getId(); + + Node node = graphDb.getNodeById(id); + + Iterable<Relationship> relIter = node.getRelationships(); + long count = 0; + // compute number of relationship. + for (Relationship rel : relIter) { + if (ltn.isHasLink(rel)) + count++; + } + w.setOutLink(count); + + relHash.put(title, count); + + if (maxRelCount < count) { + maxRelCount = count; + tmpKey = title; + } + relKeyHash.put(count, id); + } - Iterable<Relationship> relIter = node.getRelationships(); - long count = 0; - for (Relationship rel : relIter) { - if ( ltn.isHasLink(rel)) - count++; - } - relHash.put(key, count); - - if (maxRelCount < count ) { - maxRelCount = count; - tmpKey = key; + for (String title: wikiHash.keySet()) { + System.out.println(title); } - relKeyHash.put(count, id); - } - - System.out.println("AllNodeNumber = "+ AllNodeNumber); - System.out.println("Most :\n"+tmpKey+":"+maxRelCount); - + + System.out.println("AllNodeNumber = " + AllNodeNumber); + System.out.println("Most :\n" + tmpKey + ":" + maxRelCount); - - String output = ""; - Node n = graphDb.getNodeById(1); - Traverser hasLinkTraverser = ltn.getInHasLink( n ); - System.out.println(n.getProperty(LinkToNode.PAGE_TITLE)); - for (Path hasLinkPath : hasLinkTraverser) { - output = "At depth" + hasLinkPath.length() + " => " - + hasLinkPath.endNode().getProperty(LinkToNode.PAGE_TITLE) + "\n"; + String output = ""; + Node n = graphDb.getNodeById(1); + Traverser hasLinkTraverser = ltn.getInHasLink(n); + System.out.println(n.getProperty(LinkToNode.PAGE_TITLE)); + for (Path hasLinkPath : hasLinkTraverser) { + if (hasLinkPath.length() > 1) break; + output = "At depth" + + hasLinkPath.length() + + " => " + + hasLinkPath.endNode().getProperty( + LinkToNode.PAGE_TITLE) + "\n"; + System.out.println(output); + } + System.out.println(output); - } - - System.out.println(output); } catch (Exception e) { e.printStackTrace(); @@ -86,7 +94,7 @@ tx.finish(); graphDb.shutdown(); } - + } - + }