Mercurial > hg > Members > nobuyasu > TestNeo4j
changeset 19:e01c8a8190cc draft
fix LinkToNode.java
author | one |
---|---|
date | Fri, 24 Aug 2012 00:06:24 +0900 |
parents | 7e4aa7037c7c |
children | 2c3a10047ec6 |
files | src/wikigraph/LinkConvertGraph.java |
diffstat | 1 files changed, 27 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/src/wikigraph/LinkConvertGraph.java Thu Aug 23 18:49:47 2012 +0900 +++ b/src/wikigraph/LinkConvertGraph.java Fri Aug 24 00:06:24 2012 +0900 @@ -15,6 +15,7 @@ import javax.xml.parsers.SAXParserFactory; import org.neo4j.graphdb.GraphDatabaseService; +import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Transaction; import org.neo4j.kernel.EmbeddedGraphDatabase; import org.xml.sax.SAXException; @@ -90,47 +91,53 @@ // final String filename = "~/testProgram/wiki/ja-pages_current.xml"; LinkConvertGraph lcg; + + try { +/* lcg = new LinkConvertGraph(filename); lcg.parseXml(); - - /* - final String logFile = "./resource/log2.txt"; - FileOutputStream os = new FileOutputStream(logFile); - - lcg.printHash(os); - os.close(); -*/ 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(); + String pageTitle = map.getKey(); - if ( ! ltn.addName(page_title) ) { - ltn.createNodeWithPageTitle(page_title); + Node pageNode; + if ( ltn.getId(pageTitle) == null) { + pageNode = ltn.createNodeWithPageTitle(pageTitle); + } else { + pageNode = ltn.getNode(pageTitle); } - - + for (String linkPageTitle : map.getValue()) { + Node linkNode; + if ( ltn.getId(linkPageTitle) == null) { + linkNode = ltn.createNodeWithPageTitle(linkPageTitle); + } else { + linkNode = ltn.getNode(linkPageTitle); + } + ltn.setHasLink(pageNode, linkNode); + + } } - +*/ - + ltn.printAllNodes(); tx.success(); tx.finish(); graphDb.shutdown(); - +/* } catch (FileNotFoundException e) { e.printStackTrace(); } catch (SAXException e) { @@ -141,11 +148,8 @@ System.err.println("Failed to parse xml"); e.printStackTrace(); } +*/ - - - - - + }finally {} } }