Mercurial > hg > Members > nobuyasu > TestNeo4j
view src/wikigraph/ReadWikiLink.java @ 20:2c3a10047ec6 draft
add ReadWikiLink.java and LinkToNode.java
author | one |
---|---|
date | Mon, 27 Aug 2012 04:30:53 +0900 |
parents | |
children | f9ef906676eb |
line wrap: on
line source
package wikigraph; import java.util.HashMap; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.Transaction; import org.neo4j.kernel.EmbeddedGraphDatabase; public class ReadWikiLink { public static void main(String[] args) { GraphDatabaseService graphDb = new EmbeddedGraphDatabase("wikiLinkDB"); LinkToNode ltn = new LinkToNode(graphDb); Transaction tx = graphDb. beginTx(); // ltn.printAllNodes(); ltn.searchPageTitleAllNodes(); HashMap<String,Long> hash = ltn.getNamesTable(); 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); } long relCount = 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 : hash.keySet()) { long id = hash.get(key); Node node = graphDb.getNodeById(id); Iterable<Relationship> relIter = node.getRelationships(); long count = 0; for (Relationship rel : relIter) { count++; } relHash.put(key, count); if (relCount < count ) { relCount = 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); for (long i = relKeyHash.size()-1 ; i>0 ; i-- ) { long id = relKeyHash.get(i); Node node = graphDb.getNodeById(id); System.out.prinln(); } tx.success(); tx.finish(); graphDb.shutdown(); } }