停止neo4j竞争执行命令

vngu2lb8  于 2023-04-20  发布在  其他
关注(0)|答案(1)|浏览(106)

在我下面的代码块中,有时会创建DataFrame,有时则不会。
看起来这个问题是由于neo4j正在竞相执行命令的事实。我已经尝试将运行命令分成多个会话,就像下面的代码一样,我也尝试将它们全部包含在一个会话中。然而,返回的次数的一致性仍然很低。我如何才能停止这种急切的操作?

set_label_query = """
MATCH (s:Startup)
WHERE "{vertical_original}" IN s.Verticals
WITH s
MATCH (s)<-[:INVESTOR_INVESTED_IN]-(i:Investor)
WITH s, i
MATCH(i)<-[:MADE_LP_COMMITMENT_TO_VC]-(l:Limited_Partner)
SET i:{vertical}, l:{vertical}, s:{vertical}
RETURN COUNT(i)
;
"""
create_gds_project_query = '''
CALL gds.graph.project(
        'climate_cleantech_undirected',
        ['{vertical}', 'Limited_Partner', 'Investor', 'Startup'],
        {{INVESTOR_INVESTED_IN: {{orientation: 'UNDIRECTED'}},
        MADE_LP_COMMITMENT_TO_VC: {{orientation: 'UNDIRECTED'}}
        }}
        );
'''

create_rank_query = '''
CALL gds.pageRank.stream('climate_cleantech_undirected', {{
            nodeLabels:['{vertical}'] ,
            maxIterations: 20,
            dampingFactor: 0.85
        }})
        YIELD nodeId, score
        WITH gds.util.asNode(nodeId) AS node, score
        WHERE 'Investor' IN labels(node)
        RETURN node.Name, node.Website, score
        ORDER BY score DESC;
'''

remove_graph_query = "CALL gds.graph.drop('climate_cleantech_undirected', false)"
with neo4j_driver.session() as session:
    with session.begin_transaction() as tx:
        tx.run(set_label_query.format(vertical=vertical))
        tx.run(create_gds_project_query.format(vertical=vertical))
        result_data = tx.run(create_rank_query.format(vertical=vertical)).data()
        df = pd.DataFrame(result_data)
        print(df)
        tx.commit()
print('execute 2')
with neo4j_driver.session() as session:
    with session.begin_transaction() as tx:
        tx.run(remove_label_query.format(vertical=vertical))
        tx.run(remove_graph_query)
        tx.commit()

返回时的结果:

kdfy810k

kdfy810k1#

看起来set_label_query期望{vertical_original}被替换为某个值,但您的代码只将{vertical}替换为一个值。因此,set_label_query最终什么也不做。

相关问题