1

我想在 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)搜索对于节点和其他任何内容。这可以作为访问此问题的任何人的快速参考。谢谢。

4

2 回答 2

6

只需使用 node.setProperty 或 relationship.setProperty 设置属性

搜索:您可以使用 Cypher 执行查询以取回节点、属性和关系,或者您可以使用索引来查找节点,然后执行 node.getProperty。

手册中的所有内容:http: //docs.neo4j.org/chunked/stable/tutorials-java-embedded.html (假设您根据您的代码使用嵌入式)

顺便说一句: tx.success() 需要在您完成节点/rel 操作后调用。

于 2013-02-21T10:23:23.810 回答
0

这是我一直在看的一堆要点:http: //gist.neo4j.org/

可能会让您了解如何推进您的项目。

于 2015-09-29T14:51:22.797 回答