neo4j驱动程序函数等效于py2neo函数

问题描述

def get_nlg(graph_query):
    driver = Graph("neo4j://localhost:7687",auth=("neo4j","password"))
    graph_response = graph.evaluate(graph_query)

对于上面的代码,我用下面的驱动程序代码替换了,但它不起作用,neo4j驱动程序中的功能等同于py2neo中的 evaluate()功能

    def get_nlg(graph_query):
        driver = GraphDatabase.driver("neo4j://localhost:7687","password"))

        with driver.session() as session:
            graph_response = session.run(graph_query)
            return graph_response

将第二个代码 graph_response 的结果传递给下面的代码时,出现错误

TypeError:位于0x7f94cf7f31d0>的

class GetBiggestComponent(Action):
    def name(self):
        return "action_get_biggest_component"

    def run(self,dispatcher,tracker,domain):
        query = None
        intent = tracker.latest_message['intent']
        child_comp = tracker.get_slot('component_type_child')
        parent_comp = tracker.get_slot('component_type_parent')
        error = None
        graph_response = GenerateQuery.get_biggest_component(child_comp,parent_comp)
        graph_response['intent_name'] = intent['name']
        dispatcher.utter_custom_message(graph_response)
        return []

在行中传递错误时会出现

dispatcher.utter_custom_message(graph_response)

解决方法

没有直接的等效项。您将需要run查询,然后从返回的第一条记录中选择第一个值。这就是evaluate在幕后所做的一切。