# HG changeset patch # User one # Date 1346132293 -32400 # Node ID 21902773e5301bec03fd452c7f6bceffe34b28a4 # Parent 2be3358689cb818aaf291d8c40e3fa3cfd44f04a fix ReadWikiLink.java diff -r 2be3358689cb -r 21902773e530 src/wikigraph/LinkToNode.java --- a/src/wikigraph/LinkToNode.java Tue Aug 28 14:04:46 2012 +0900 +++ b/src/wikigraph/LinkToNode.java Tue Aug 28 14:38:13 2012 +0900 @@ -24,10 +24,11 @@ public final static String PAGE_TITLE = "page_title"; public final static String PAGE_RANK = "page_rank"; -// private HashSet names = new HashSet(); private HashMap pageIdTable = new HashMap(); private HashMap pageRankTable = new HashMap(); + private HashMap wikiPageHash = new HashMap(); + public enum RelTypes implements RelationshipType { HAS_LINK } @@ -117,6 +118,18 @@ return AllNodeNumber; } + long searchAllNodes() { + long AllNodeNumber = 0; + for (Node n: graphOpe.getAllNodes()) { + if (n.hasProperty(PAGE_TITLE)) { + WikiPage wiki = new WikiPage(n); + wikiPageHash.put((String)n.getProperty(PAGE_TITLE), wiki); + AllNodeNumber++; + } + } + return AllNodeNumber; + } + HashMap getPageIdTable() { return pageIdTable; } @@ -125,6 +138,10 @@ return pageRankTable; } + HashMap getWikiPageHash() { + return wikiPageHash; + } + public void printAllNodes() { for (Node n: graphOpe.getAllNodes()) { System.out.println("ID="+ n.getId()); diff -r 2be3358689cb -r 21902773e530 src/wikigraph/ReadWikiLink.java --- 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 pageIdHash = ltn.getPageIdTable(); - HashMap pageRankHash = ltn.getPageRankTable(); - - long maxRelCount = 0; - String tmpKey=""; - // relHash record number of relationships of each node. - // Key: page_title value: number of relationships - HashMap relHash = new HashMap(); - - // relKeyHash - // key: number of relationships value: ID - HashMap relKeyHash = new HashMap(); - - 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 relHash = new HashMap(); + + // relKeyHash + // key: number of relationships value: ID + HashMap relKeyHash = new HashMap(); + + HashMap wikiHash = ltn.getWikiPageHash(); + + for (String title: wikiHash.keySet()) { + WikiPage w = wikiHash.get(title); + long id = w.getId(); + + Node node = graphDb.getNodeById(id); + + Iterable 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 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(); } - + } - + } diff -r 2be3358689cb -r 21902773e530 src/wikigraph/WikiPage.java --- a/src/wikigraph/WikiPage.java Tue Aug 28 14:04:46 2012 +0900 +++ b/src/wikigraph/WikiPage.java Tue Aug 28 14:38:13 2012 +0900 @@ -7,23 +7,31 @@ private String title; private long id; private long rank; + private long outLink; + private long inLink; WikiPage() { - this.title = ""; - this.id = 0; - this.rank = 0; + this.title = null; + this.id = -1; + this.rank = -1; + this.outLink = 0; + this.inLink = 0; } WikiPage(Node node) { this.title = (String) node.getProperty(LinkToNode.PAGE_TITLE); this.id = node.getId(); this.rank = (Long) node.getProperty(LinkToNode.PAGE_RANK); + this.outLink = 0; + this.inLink = 0; } WikiPage(String title, long id, long rank) { this.title = title; this.id = id; this.rank = rank; + this.outLink = 0; + this.inLink = 0; } String getTitle() { @@ -38,6 +46,14 @@ return rank; } + long getOutLink() { + return outLink; + } + + long getInLink() { + return inLink; + } + void setTitle(String title) { this.title = title; } @@ -49,5 +65,13 @@ void setRank(long rank) { this.rank = rank; } + + void setOutLink(long num) { + this.outLink = num; + } + + void setInLink(long num) { + this.inLink = num; + } }