不幸的是,由于 neo4j 内部的一些政治因素,py2neo 项目现已停产并已从 pypi 中删除。请参阅此推特主题。
有没有人可能已经分叉了 GitHub 存储库?
我想在neo4j(java)中根据Facebook数据构建社交网络图.我正在尝试搜索相关的示例来理解这些概念,但仍然无法获得任何这些特定类型.请帮助我知道如何实现它,如果可能的话,提供适当的链接,我可以获得相关的帮助.
我想拥有节点和关系(边缘)属性,如下所示:
Node properties:
String id, name, town;
int numOfFriends;
Double age;
Date dateOfJoining
HashSet<String> postIdSet;
Relationship Properties:
boolean Knows;
int numOfLikes, numOfComments;
float wtLikes, wtComments;
String relationship;
Run Code Online (Sandbox Code Playgroud)
如何创建graphDB具有上述属性的节点和边?
我有一个示例代码结构,用于创建graphDB和添加节点和关系,如下所示:
GraphDatabaseService graphDB = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
registerShutdownHook(graphDB);
Transaction tx = graphDB.beginTx();
try {
/* define relationshipType*/
RelationshipType rel = DynamicRelationshipType.withName(??);
/* create new node with given properties*/
Node node1 = graphDB.createNode();
/* set node1 properties e.g. node1.id="1234" */
/* create another new node with given properties */ …Run Code Online (Sandbox Code Playgroud) 在这里,他们将类型设置为每个顶点上的属性.但是,如果我想给类型一些属性呢?在这种情况下,创建一个顶点来表示一个类型并让每个其他顶点都有一个"类型"边缘会不会更有意义?否则我最终会复制一个类型的属性.
如果我想要检索特定类型的所有顶点,这个额外的间接层是否会对性能产生重大影响?
我正在使用Titan 0.4 + Cassandra。我的用例需要一次插入多个顶点。(aprrox批处理大小一次是100个顶点。)例如:
v01 = g.addVertex(["UC":"B","i":2]); v02 = g.addVertex(["UC":"H","i":1])
v03 = g.addVertex(["LC":"a"]); v04 = g.addVertex(["LC":"a"]);
v05 = g.addVertex(["LC":"d"]); v06 = g.addVertex(["LC":"h"]);
v07 = g.addVertex(["LC":"i"]); v08 = g.addVertex(["LC":"p"]);
Run Code Online (Sandbox Code Playgroud)
是否有任何gremlin命令添加全部Eight vertices in a single request。(类似 g.addVertices()??)
我有顶点User1和User2.当User1访问User2配置文件时,添加一个带有count变量的边(即已访问).
当User1再次访问User2配置文件时,如何增加计数变量.
我有一个用例,我需要在neo4j中的并行线程中运行我的存储过程.我编写了存储过程并将其包含在neo4j插件中.但是当我运行存储过程时,我得到以下错误:
2016-06-24 05:45:54.683+0000 INFO Remote interface available at http://localhost:7474/
java.lang.UnsupportedOperationException: Creating new transactions and/or spawning threads are not supported operations in store procedures.
at org.neo4j.kernel.impl.proc.ProcedureGDBFacadeSPI.assertSameThread(ProcedureGDBFacadeSPI.java:108)
at org.neo4j.kernel.impl.proc.ProcedureGDBFacadeSPI.isInOpenTransaction(ProcedureGDBFacadeSPI.java:124)
at org.neo4j.kernel.impl.factory.GraphDatabaseFacade.beginTransaction(GraphDatabaseFacade.java:335)
at org.neo4j.kernel.impl.factory.GraphDatabaseFacade.beginTx(GraphDatabaseFacade.java:330)
at example.SearchTask.call(SearchTask.java:33)
at example.SearchTask.call(SearchTask.java:17)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Run Code Online (Sandbox Code Playgroud)
我已经明白,在neo4j中自定义存储过程无法在并行线程中运行.
但我在寻找有什么方法可以并行运行它.
我已经死了泰坦新手,当我开始研究它时,我感到很困惑,因为它有很多新东西,如Gremlin,tinkerpop和rexter等.
我想要的是java中的一个例子,它使用Titan和Cassandra作为后端.我想创建一个图形,存储在cassandra中,检索它并遍历它.一个非常简单的也会很有帮助.
我在java中运行了一个基本的例子.
BaseConfiguration baseConfiguration = new BaseConfiguration();
baseConfiguration.setProperty("storage.backend", "cassandra");
baseConfiguration.setProperty("storage.hostname", "192.168.3.82");
TitanGraph titanGraph = TitanFactory.open(baseConfiguration);
Vertex rash = titanGraph.addVertex(null);
rash.setProperty("userId", 1);
rash.setProperty("username", "rash");
rash.setProperty("firstName", "Rahul");
rash.setProperty("lastName", "Chaudhary");
rash.setProperty("birthday", 101);
Vertex honey = titanGraph.addVertex(null);
honey.setProperty("userId", 2);
honey.setProperty("username", "honey");
honey.setProperty("firstName", "Honey");
honey.setProperty("lastName", "Anant");
honey.setProperty("birthday", 201);
Edge frnd = titanGraph.addEdge(null, rash, honey, "FRIEND");
frnd.setProperty("since", 2011);
titanGraph.shutdown();
Run Code Online (Sandbox Code Playgroud)
所以当我运行它时,我观察了cassandra日志并创建了一个名为titan的键空间和下表:
我不知道这些表的用途以及它们如何存储数据.
运行程序后,会创建一个包含2个顶点和它们之间边缘的图形.我查询了表格,并在每个表格中找到了一些十六进制值.
我有以下问题:
如何将图存储在cassandra中?
现在我有这个图表说'x'存储在cassandra中.假设我创建了另一个图形'y'并存储它.如何检索和遍历任何特定图表?因为在正常的cql查询中,您知道要查询的表和列.我将如何分别识别'x'和'y'.
任何人都可以帮助在java中发布示例代码,以使用一些示例csv数据创建图形.存储在Cassandra和一些相同图形的遍历示例.会有很多帮助,因为没有可用的例子是可以理解的.
我浏览了JanusGraph和Titan文档,它不断在管理对象上调用其他函数,如"makeEdgeLabel"等,但是我无法理解Management类的确切用法,因为根据我的理解,我可以在"JanusGraph"上调用相同的函数同样.
我想了解JanusGraph中所谓的"管理系统"的确切含义.
我使用Microsoft.Azure.Graphs库连接到Cosmos数据库实例并查询图数据库.
我正在尝试优化我的Gremlin查询,以便只选择我只需要的那些属性.但是,我不知道如何选择从边和顶点中选择哪些属性.
假设我们从这个查询开始:
gremlin> g.V().hasLabel('user').
project('user', 'edges', 'relatedVertices')
.by()
.by(bothE().fold())
.by(both().fold())
Run Code Online (Sandbox Code Playgroud)
这将返回以下内容:
{
"user": {
"id": "<userId>",
"type": "vertex",
"label": "user",
"properties": [
// all vertex properties
]
},
"edges": [{
"id": "<edgeId>",
"type": "edge",
"label": "<edgeName>",
"inV": <relatedVertexId>,
"inVLabel": "<relatedVertexLabel>",
"outV": "<relatedVertexId>",
"outVLabel": "<relatedVertexLabel>"
"properties": [
// edge properties, if any
]
}],
"relatedVertices": [{
"id": "<vertexId>",
"type": "vertex",
"label": "<relatedVertexLabel>",
"properties": [
// all related vertex properties
]
}]
}
Run Code Online (Sandbox Code Playgroud)
现在假设我们只从我们命名为"User"的根顶点获取一些属性:
gremlin> g.V().hasLabel('user').
project('id', 'prop1', 'prop2', 'edges', 'relatedVertices') …Run Code Online (Sandbox Code Playgroud) 我想从路径中删除一个节点,而不会危及原始路径节点.
这是我的测试数据库:
我想从路径中删除node(2),但我希望节点1,3,4和5在路径中保持链接.
有没有办法在一个查询中执行此操作?到目前为止,我有以下内容:
MATCH p = (:Connect)-[:to*]-(:Connect)
WITH nodes(p) AS connectNodes
UNWIND connectNodes AS connectNode
WITH distinct connectNode
WHERE connectNode.connectID = 2
DETACH DELETE (connectNode)
Run Code Online (Sandbox Code Playgroud)
这将删除节点2并取消链接路径
如何在没有节点2的情况下维护原始路径的节点之间的链接?
编辑:
我通过修改接受的答案的答案来解决它
//Make sure node (n) belongs to the path
MATCH (n:Connect {cID:2})-[:to*]-(:Connect {cID:5})
//get attached nodes, if any, ignoring directions
OPTIONAL MATCH (oa:connect)-[:to]-(n)-[:to]-(ob:connect)
//make sure nothing is duplicated
WHERE oa.cID <> ob.cID
//Use FOREACH to mimic if/else. Only merge oa to ob if they exist. Query fails without it
FOREACH …Run Code Online (Sandbox Code Playgroud)