Mercurial > hg > Members > nobuyasu > TestNeo4j
diff src/wikigraph/ReadWikiLink.java @ 21:f9ef906676eb draft
modify LinkToNode.java
author | one |
---|---|
date | Tue, 28 Aug 2012 14:04:15 +0900 |
parents | 2c3a10047ec6 |
children | 21902773e530 |
line wrap: on
line diff
--- a/src/wikigraph/ReadWikiLink.java Mon Aug 27 04:30:53 2012 +0900 +++ b/src/wikigraph/ReadWikiLink.java Tue Aug 28 14:04:15 2012 +0900 @@ -1,12 +1,18 @@ package wikigraph; import java.util.HashMap; +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 { @@ -15,23 +21,19 @@ GraphDatabaseService graphDb = new EmbeddedGraphDatabase("wikiLinkDB"); - LinkToNode ltn = new LinkToNode(graphDb); + GlobalGraphOperations graphOpe = GlobalGraphOperations.at(graphDb); + LinkToNode ltn = new LinkToNode(graphDb, graphOpe); Transaction tx = graphDb. beginTx(); - -// ltn.printAllNodes(); - - ltn.searchPageTitleAllNodes(); - HashMap<String,Long> hash = ltn.getNamesTable(); - + + try { + + final long AllNodeNumber = ltn.searchPageTitleAllNodes(); - long lastNodeId = 0; - // Print out page title and ID of All Node. - for (String key : hash.keySet()) { -// System.out.println("page title = "+key + "\nID = " + hash.get(key)); - lastNodeId = Math.max(hash.get(key), lastNodeId); - } + // Key: page_title value: Node ID + HashMap<String,Long> pageIdHash = ltn.getPageIdTable(); + HashMap<String,Long> pageRankHash = ltn.getPageRankTable(); - long relCount = 0; + long maxRelCount = 0; String tmpKey=""; // relHash record number of relationships of each node. // Key: page_title value: number of relationships @@ -41,41 +43,49 @@ // key: number of relationships value: ID HashMap<Long,Long> relKeyHash = new HashMap<Long,Long>(); - for (String key : hash.keySet()) { - long id = hash.get(key); + for (String key : pageIdHash.keySet()) { + long id = pageIdHash.get(key); Node node = graphDb.getNodeById(id); Iterable<Relationship> relIter = node.getRelationships(); long count = 0; for (Relationship rel : relIter) { - count++; + if ( ltn.isHasLink(rel)) + count++; } relHash.put(key, count); - if (relCount < count ) { - relCount = count; + if (maxRelCount < count ) { + maxRelCount = count; tmpKey = key; } relKeyHash.put(count, id); } - for (String key : relHash.keySet()) { -// System.out.println(key + ":"+relHash.get(key)); - } - System.out.println("lastNodeId = "+ lastNodeId); - System.out.println("Most :\n"+tmpKey+":"+relCount); + System.out.println("AllNodeNumber = "+ AllNodeNumber); + System.out.println("Most :\n"+tmpKey+":"+maxRelCount); - for (long i = relKeyHash.size()-1 ; i>0 ; i-- ) { - long id = relKeyHash.get(i); - Node node = graphDb.getNodeById(id); - System.out.prinln(); + + 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"; + System.out.println(output); } - - tx.success(); - tx.finish(); - graphDb.shutdown(); + System.out.println(output); + + } catch (Exception e) { + e.printStackTrace(); + } finally { + tx.success(); + tx.finish(); + graphDb.shutdown(); + } }