用户登录
用户注册

分享至

neo4j java依赖库 jar

  • 作者: 期望4405047
  • 来源: 51数据库
  • 2020-09-30
您好,很高兴为您解答:
  Neo4j是一个嵌入式,基于磁盘的,支持完整事务的Java持久化引擎,它在图像中而不是表中存储数据。Neo4j提供了大规模可扩展性,在一台机器上可以处理数十亿节点/关系/属性的图像,可以扩展到多台机器并行运行。
  相对于关系数据库来说,图形数据库善于处理大量复杂、互连接、低结构化的数据,这些数据变化迅速,需要频繁的查询——在关系数据库中,这些查询会导致大量的表连接,因此会产生性能上的问题。
  Neo4j重点解决了拥有大量连接的传统RDBMS在查询时出现的性能衰退问题。通过围绕图形进行数据建模,Neo4j会以相同的速度遍历节点与边,其遍历速度与构成图形的数据量没有任何关系。
  此外,Neo4j还提供了非常快的图形算法、推荐系统和OLAP风格的分析,而这一切在目前的RDBMS系统中都是无法实现的。

  转载,仅供参考。



  package com.neo4j; import java.io.file; import java.io.ioexception; import org.neo4j.graphdb.direction; import org.neo4j.graphdb.graphdatabaseservice; import org.neo4j.graphdb.node; import org.neo4j.graphdb.path; import org.neo4j.graphdb.relationship; import org.neo4j.graphdb.relationshiptype; import org.neo4j.graphdb.factory.graphdatabasefactory; import org.neo4j.graphdb.transaction; import org.neo4j.graphdb.index.index; import org.neo4j.graphdb.traversal.evaluators; import org.neo4j.graphdb.traversal.traverser; import org.neo4j.graphdb.traversal.traversaldescription; import org.neo4j.kernel.traversal; import org.neo4j.kernel.impl.util.fileutils; import org.neo4j.kernel.impl.util.stringlogger; import org.neo4j.cypher.executionengine; import org.neo4j.cypher.executionresult; import org.neo4j.graphalgo.pathfinder; import org.neo4j.graphalgo.graphalgofactory; public class example { // private static final string db_path = "target/neo4jexample"; private static final string db_path = "testgraph.db"; private static final string primary_key = "name"; private graphdatabaseservice graphdb; private index<node> nodeindex; private long startnodeid; private static enum reltypes implements relationshiptype { neo_node, knows, coded_by } private void cleardb() { try { fileutils.deleterecursively(new file(db_path)); } catch(ioexception e) { throw new runtimeexception(e); } } public void createdb() { cleardb(); graphdb = new graphdatabasefactory().newembeddeddatabase(db_path); nodeindex = graphdb.index().fornodes("nodes"); registershutdownhook(graphdb); transaction tx = graphdb.begintx(); try { node startnode = graphdb.createnode(); startnodeid = startnode.getid(); node thomas = graphdb.createnode(); thomas.setproperty( "name", "thomas anderson" ); thomas.setproperty( "age", 29 ); nodeindex.add(thomas, primary_key, thomas.getproperty("name")); startnode.createrelationshipto( thomas, reltypes.neo_node ); node trinity = graphdb.createnode(); trinity.setproperty( "name", "trinity" ); nodeindex.add(trinity, primary_key, trinity.getproperty("name")); relationship rel = thomas.createrelationshipto( trinity, reltypes.knows ); rel.setproperty( "age", "3 days" ); node morpheus = graphdb.createnode(); morpheus.setproperty( "name", "morpheus" ); morpheus.setproperty( "rank", "captain" ); morpheus.setproperty( "occupation", "total badass" ); nodeindex.add(morpheus, primary_key, morpheus.getproperty("name")); thomas.createrelationshipto( morpheus, reltypes.knows ); rel = morpheus.createrelationshipto( trinity, reltypes.knows ); rel.setproperty( "age", "12 years" ); node cypher = graphdb.createnode(); cypher.setproperty( "name", "cypher" ); cypher.setproperty( "last name", "reagan" ); nodeindex.add(cypher, primary_key, cypher.getproperty("name")); trinity.createrelationshipto( cypher, reltypes.knows ); rel = morpheus.createrelationshipto( cypher, reltypes.knows ); rel.setproperty( "disclosure", "public" ); node smith = graphdb.createnode(); smith.setproperty( "name", "agent smith" ); smith.setproperty( "version", "1.0b" ); smith.setproperty( "language", "c++" ); nodeindex.add(smith, primary_key, smith.getproperty("name")); rel = cypher.createrelationshipto( smith, reltypes.knows ); rel.setproperty( "disclosure", "secret" ); rel.setproperty( "age", "6 months" ); node architect = graphdb.createnode(); architect.setproperty( "name", "the architect" ); nodeindex.add(architect, primary_key, architect.getproperty("name")); smith.createrelationshipto( architect, reltypes.coded_by ); tx.success(); } finally { tx.finish(); } } public traverser getfriends(final node person) { traversaldescription td = traversal.description() .breadthfirst() .relationships(reltypes.knows, direction.outgoing) .evaluator(evaluators.excludestartposition()); return td.traverse(person); } public void printnodefriends(node node) { // node neo = graphdb.getnodebyid(startnodeid) // .getsinglerelationship(reltypes.neo_node, direction.outgoing) // .getendnode(); int friendsnumbers = 0; system.out.println(node.getproperty(primary_key) + "&apos;s friends:"); for(path friendpath: getfriends(node)) { system.out.println("at depth " + friendpath.length() + " => " + friendpath.endnode().getproperty(primary_key)); friendsnumbers++; } system.out.println("number of friends found: " + friendsnumbers); } public void printcypherfriends(string name) { graphdb = new graphdatabasefactory().newembeddeddatabase(db_path); executionengine engine = new executionengine(graphdb, stringlogger.logger(db_path)); // executionresult result = engine.execute( // "start n=node:nodes(name=\"" + name + "\") " // + "match n-[:knows*..]->f " // + "return distinct f, f.name"); executionresult result = engine.execute("start n=node(500000) return n;"); system.out.println(result.dumptostring()); } public void printthomasfriends() { printnodefriends(nodeindex.get(primary_key, "thomas anderson").getsingle()); } public iterable<path> findshortestpath(node node1, node node2) { pathfinder<path> finder = graphalgofactory.shortestpath( traversal.expanderfortypes(reltypes.knows, direction.outgoing), 5); iterable<path> paths = finder.findallpaths(node1, node2); return paths; } public void printshortestpaths() { node node1 = nodeindex.get(primary_key, "thomas anderson").getsingle(); node node2 = nodeindex.get(primary_key, "agent smith").getsingle(); for(path shortestpath: findshortestpath(node1, node2)) { system.out.println(shortestpath.tostring()); } } private static void registershutdownhook(final graphdatabaseservice graphdb) { runtime.getruntime().addshutdownhook(new thread() { @override public void run() { graphdb.shutdown(); } }); } private void shutdown() { graphdb.shutdown(); } /** * @param args */ public static void main(string[] args) { example example = new example(); // example.createdb(); long t1 = system.currenttimemillis(); // example.printthomasfriends(); example.printcypherfriends("thomas anderson"); long t2 = system.currenttimemillis(); system.out.print(t2-t1); //example.printshortestpaths(); example.shutdown(); } }
软件
前端设计
程序设计
Java相关