0
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)
James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

0

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.

Nigel Small
  • 4,475
  • 1
  • 17
  • 15
  • can you please tell me how to get first value from the first record when using the function ```run```? –  Nov 13 '20 at 11:04
  • maybe a bit late, but if you make a "run" you will get back an cursor object. You can handle the cursor object by usage of something like `while cursor.forward(): result = cursor.current.data()` here the documentation: [https://py2neo.org/2021.1/cypher/index.html#py2neo.cypher.Cursor](https://py2neo.org/2021.1/cypher/index.html#py2neo.cypher.Cursor) – ottonormal Jul 22 '22 at 10:37