代码之家  ›  专栏  ›  技术社区  ›  albertovpd

Neo4j:在投影中使用与权重的虚拟关系

  •  0
  • albertovpd  · 技术社区  · 1 年前

    我可以在我的图中创建一个关系,分配权重并在磁盘中写入,如下所示:

    MATCH (a1:node1)-[rel1]-(p:other_node)-[rel2]-(a2:node2)
    // create the weight
    with a1.id as id1, a2.id as id2, count(p) as common_ocurrences
    // create the rel
    MERGE (a1)-[r:NEW_REL]-(a2)
    // use the weights as a property of the created relationship
    ON CREATE SET r.counter = common_occurrences
    ON MATCH SET r.counter = common_occurrences
    
    // create projection 
    CALL gds.graph.project(
     'new-graph',
     'node1',
     {NEW_REL:{
     orientation:'UNDIRECTED',
     properties:'counter'
     }
     }
    )
    yield *
    

    但我想做的是同样的事情,不写关系,也不写相关的权重。 为此,我尝试使用 虚拟关系 与此方法类似:

    MATCH (a1:node1)-[rel1]-(p:other_node)-[rel2]-(a2:node2)
    with a1, a2, count(p) as common_occurrences
    where a1.id>a2.id
    return 
    a1, a2, 
    apoc.create.vRelationship(a1, 'COAUTHORS_WITH_VIRTUAL2', {weight: common_occurrences}, a2) as REL_VIRTUAL2;
    

    这一部分似乎有效,但现在我对如何使用它感到困惑。如果在最后一个子句之后,我写一些类似的东西

    CALL gds.graph.project(
     'graph42',
     'node1',
     {REL_VIRTUAL_2:{
     orientation:'UNDIRECTED',
     properties:'common_occurrences'
     }
     }
    
    )
    yield *
    

    上面说找不到这种关系。 有什么帮助吗?

    0 回复  |  直到 1 年前
        1
  •  1
  •   cybersam    1 年前

    您的两个查询都存在一些问题。

    例如 REL_VIRTUAL2 只是一个临时变量名,而不是关系类型。 COAUTHORS_WITH_VIRTUAL2 是您应该在投影中使用的关系类型。然而,改变这一点仍然无法解决问题,因为 GDS不支持投影虚拟节点或关系 .

    你的第一种方法应该有效,但你可能需要先解决一些其他问题。例如,投影应使用 ['node1', 'node2'] 而不是 'node1' 对于节点标签,。你可以替换 ON CREATE SET x = y ON MATCH SET x = y 只有 SET x = y .