neo4j driver functions equivalent to py2neo functions

故事扮演 提交于 2020-12-07 16:00:16

问题


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

For the above code, I replaced with the driver code as below, but its not working, what is the function in neo4j driver equivalent to evaluate() function in py2neo?

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

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

When the result from graph_response of 2nd code is passed to the below code, I am getting an error

TypeError: <neo4j.work.result.Result object at 0x7f94cf7f31d0> is not JSON serializable

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 []

the error is coming when it is passed in the line

dispatcher.utter_custom_message(graph_response)

回答1:


There is no direct equivalent. You will need to run a query and then select the first value from the first record returned. That is all that evaluate does behind the scenes.



来源:https://stackoverflow.com/questions/64800042/neo4j-driver-functions-equivalent-to-py2neo-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!