N D*_*are 1 java edges nodes neo4j graph-databases
我想在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 */
Node node2 = graphDB.createNode();
/* set node2 properties e.g. node1.id="5678" */
/* search for node with id "1234" */
Node n1 = getNodeById(graphDB,"1234");
/* search for node with id "5678" */
Node n2 = getNodeById(graphDB,"5678");
/* create relationship between n1 and n2 with above mentioned properties and set their values */
Relationship relationship = n1.createRelationshipTo(n2, rel);
relationship.setProperty(??);
tx.success();
} finally {
tx.finish();
}
Run Code Online (Sandbox Code Playgroud)
如何将这些不同的属性添加到节点或边缘(关系)?
如何搜索具有给定String "id"
属性的节点并更新其他属性,例如numOfFriends
?
如果有人试图填充/提供所有/任何查询的示例解决方案代码,那将是最有用的:(1)添加给定的节点属性集,(2)添加给定的边缘属性集,(3)搜索对于节点和其他任何附加..这可以作为访问这个问题的任何人的快速参考..谢谢.
只需使用node.setProperty或relationship.setProperty设置属性即可
搜索:您可以使用Cypher执行查询以获取节点,属性和关系,或者使用索引查找节点然后执行node.getProperty.
全部在手册中:http://docs.neo4j.org/chunked/stable/tutorials-java-embedded.html (假设您根据代码使用嵌入式)
BTW:完成节点/ rel操作后需要调用tx.success().
归档时间: |
|
查看次数: |
3667 次 |
最近记录: |