# HG changeset patch # User one # Date 1345715387 -32400 # Node ID 7e4aa7037c7c3d65bb43f159217eeacca6b7488c # Parent e30f2714686b3395e7d1fffee9823052d692273b modify LinkToNode.java diff -r e30f2714686b -r 7e4aa7037c7c src/wikigraph/LinkConvertGraph.java --- 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> hash = lcg.getHash(); + + GraphDatabaseService graphDb = new EmbeddedGraphDatabase("db"); + LinkToNode ltn = new LinkToNode(graphDb); + + Transaction tx = graphDb. beginTx(); + + for (Map.Entry> 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(); } + + + + + } } diff -r e30f2714686b -r 7e4aa7037c7c src/wikigraph/Neo4jTest.java --- 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();