comparison 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
comparison
equal deleted inserted replaced
22:2be3358689cb 23:21902773e530
14 14
15 import wikigraph.LinkToNode.RelTypes; 15 import wikigraph.LinkToNode.RelTypes;
16 16
17 public class ReadWikiLink { 17 public class ReadWikiLink {
18 18
19
20 public static void main(String[] args) { 19 public static void main(String[] args) {
21
22 20
23 GraphDatabaseService graphDb = new EmbeddedGraphDatabase("wikiLinkDB"); 21 GraphDatabaseService graphDb = new EmbeddedGraphDatabase("wikiLinkDB");
24 GlobalGraphOperations graphOpe = GlobalGraphOperations.at(graphDb); 22 GlobalGraphOperations graphOpe = GlobalGraphOperations.at(graphDb);
25 LinkToNode ltn = new LinkToNode(graphDb, graphOpe); 23 LinkToNode ltn = new LinkToNode(graphDb, graphOpe);
26 Transaction tx = graphDb. beginTx(); 24 Transaction tx = graphDb.beginTx();
27 25
28 try { 26 try {
27
28 // final long AllNodeNumber = ltn.searchPageTitleAllNodes();
29 final long AllNodeNumber = ltn.searchAllNodes();
30
31 long maxRelCount = 0;
32 String tmpKey = "";
33 // relHash record number of relationships of each node.
34 // Key: page_title value: number of relationships
35 HashMap<String, Long> relHash = new HashMap<String, Long>();
36
37 // relKeyHash
38 // key: number of relationships value: ID
39 HashMap<Long, Long> relKeyHash = new HashMap<Long, Long>();
40
41 HashMap<String,WikiPage> wikiHash = ltn.getWikiPageHash();
42
43 for (String title: wikiHash.keySet()) {
44 WikiPage w = wikiHash.get(title);
45 long id = w.getId();
46
47 Node node = graphDb.getNodeById(id);
48
49 Iterable<Relationship> relIter = node.getRelationships();
50 long count = 0;
51 // compute number of relationship.
52 for (Relationship rel : relIter) {
53 if (ltn.isHasLink(rel))
54 count++;
55 }
56 w.setOutLink(count);
57
58 relHash.put(title, count);
59
60 if (maxRelCount < count) {
61 maxRelCount = count;
62 tmpKey = title;
63 }
64 relKeyHash.put(count, id);
65 }
29 66
30 final long AllNodeNumber = ltn.searchPageTitleAllNodes(); 67 for (String title: wikiHash.keySet()) {
31 68 System.out.println(title);
32 // Key: page_title value: Node ID 69 }
33 HashMap<String,Long> pageIdHash = ltn.getPageIdTable();
34 HashMap<String,Long> pageRankHash = ltn.getPageRankTable();
35
36 long maxRelCount = 0;
37 String tmpKey="";
38 // relHash record number of relationships of each node.
39 // Key: page_title value: number of relationships
40 HashMap<String,Long> relHash = new HashMap<String,Long>();
41
42 // relKeyHash
43 // key: number of relationships value: ID
44 HashMap<Long,Long> relKeyHash = new HashMap<Long,Long>();
45
46 for (String key : pageIdHash.keySet()) {
47 long id = pageIdHash.get(key);
48 Node node = graphDb.getNodeById(id);
49 70
50 Iterable<Relationship> relIter = node.getRelationships(); 71 System.out.println("AllNodeNumber = " + AllNodeNumber);
51 long count = 0; 72 System.out.println("Most :\n" + tmpKey + ":" + maxRelCount);
52 for (Relationship rel : relIter) { 73
53 if ( ltn.isHasLink(rel)) 74 String output = "";
54 count++; 75 Node n = graphDb.getNodeById(1);
76 Traverser hasLinkTraverser = ltn.getInHasLink(n);
77 System.out.println(n.getProperty(LinkToNode.PAGE_TITLE));
78 for (Path hasLinkPath : hasLinkTraverser) {
79 if (hasLinkPath.length() > 1) break;
80 output = "At depth"
81 + hasLinkPath.length()
82 + " => "
83 + hasLinkPath.endNode().getProperty(
84 LinkToNode.PAGE_TITLE) + "\n";
85 System.out.println(output);
55 } 86 }
56 relHash.put(key, count);
57 87
58 if (maxRelCount < count ) {
59 maxRelCount = count;
60 tmpKey = key;
61 }
62 relKeyHash.put(count, id);
63 }
64
65 System.out.println("AllNodeNumber = "+ AllNodeNumber);
66 System.out.println("Most :\n"+tmpKey+":"+maxRelCount);
67
68
69
70 String output = "";
71 Node n = graphDb.getNodeById(1);
72 Traverser hasLinkTraverser = ltn.getInHasLink( n );
73 System.out.println(n.getProperty(LinkToNode.PAGE_TITLE));
74 for (Path hasLinkPath : hasLinkTraverser) {
75 output = "At depth" + hasLinkPath.length() + " => "
76 + hasLinkPath.endNode().getProperty(LinkToNode.PAGE_TITLE) + "\n";
77 System.out.println(output); 88 System.out.println(output);
78 }
79
80 System.out.println(output);
81 89
82 } catch (Exception e) { 90 } catch (Exception e) {
83 e.printStackTrace(); 91 e.printStackTrace();
84 } finally { 92 } finally {
85 tx.success(); 93 tx.success();
86 tx.finish(); 94 tx.finish();
87 graphDb.shutdown(); 95 graphDb.shutdown();
88 } 96 }
89 97
90 } 98 }
91 99
92 } 100 }