changeset 18:7e4aa7037c7c draft

modify LinkToNode.java
author one
date Thu, 23 Aug 2012 18:49:47 +0900
parents e30f2714686b
children e01c8a8190cc
files src/wikigraph/LinkConvertGraph.java src/wikigraph/Neo4jTest.java
diffstat 2 files changed, 48 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/wikigraph/LinkConvertGraph.java	Thu Aug 23 17:36:46 2012 +0900
+++ b/src/wikigraph/LinkConvertGraph.java	Thu Aug 23 18:49:47 2012 +0900
@@ -14,6 +14,9 @@
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 
+import org.neo4j.graphdb.GraphDatabaseService;
+import org.neo4j.graphdb.Transaction;
+import org.neo4j.kernel.EmbeddedGraphDatabase;
 import org.xml.sax.SAXException;
 
 public class LinkConvertGraph {
@@ -78,18 +81,21 @@
 		}		
 	}
 	
+	
+	
+	
+	
 	public static void main(String[] args) {
 		final String filename = "./resource/article3.xml";
 //		final String filename = "~/testProgram/wiki/ja-pages_current.xml";
 		
+		LinkConvertGraph lcg;
 		try {
-			LinkConvertGraph lcg = new LinkConvertGraph(filename);
+			lcg = new LinkConvertGraph(filename);
 
 			lcg.parseXml();
-
 			
-			
-/*
+			/*
 			final String logFile = "./resource/log2.txt";
 			FileOutputStream os = new FileOutputStream(logFile);
 			
@@ -98,7 +104,33 @@
 */
 			lcg.printHash();
 
-		
+
+			HashMap<String,HashSet<String>> hash = lcg.getHash();
+			
+			GraphDatabaseService graphDb = new EmbeddedGraphDatabase("db");
+			LinkToNode ltn = new LinkToNode(graphDb);
+			
+			Transaction tx = graphDb. beginTx();
+			
+			for (Map.Entry<String,HashSet<String>> map : hash.entrySet()) {
+				String page_title = map.getKey();
+				
+				if ( ! ltn.addName(page_title) ) {
+					ltn.createNodeWithPageTitle(page_title);
+				}
+				
+				
+				
+				
+			}
+			
+			
+			
+			
+			tx.success();
+			tx.finish();
+			graphDb.shutdown();
+			
 		} catch (FileNotFoundException e) {
 			e.printStackTrace();
 		} catch (SAXException e) {
@@ -110,5 +142,10 @@
 			e.printStackTrace();
 		}
 
+		
+		
+		
+
+
 	}
 }
--- a/src/wikigraph/Neo4jTest.java	Thu Aug 23 17:36:46 2012 +0900
+++ b/src/wikigraph/Neo4jTest.java	Thu Aug 23 18:49:47 2012 +0900
@@ -53,6 +53,10 @@
 		ranka.createRelationshipTo(alto, RelTypes.FRIEND);
 	}
 
+	public static void printType(RelationshipType type) {
+		System.out.println(type);
+	}
+	
 	public static Traverser getFriends( final Node person) {
 		TraversalDescription td = Traversal.description()
 				.breadthFirst()
@@ -111,6 +115,8 @@
    				createNodeWithProperty(graphDb, name);
    		}
    		printAllNodes(graphOpe);
+   		
+   		printType(RelTypes.FRIEND);
 
    		
 		tx.success();