我想在 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;
如何创建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();
}
如何将这些不同的属性添加到节点或边缘(关系)?
如何搜索具有给定 String"id"
属性的节点并更新它的其他属性,例如numOfFriends
?
如果有人尝试为所有/任何查询填充/提供示例解决方案代码,这将是最有用的:(1)添加给定的节点属性集,(2)添加给定的边缘属性集,(3)搜索对于节点和其他任何内容。这可以作为访问此问题的任何人的快速参考。谢谢。