相当于py2neo函数的neo4j驱动程序函数 [英] neo4j driver functions equivalent to py2neo functions

查看:409
本文介绍了相当于py2neo函数的neo4j驱动程序函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

对于上面的代码,我用下面的驱动程序代码替换了,但是它不起作用,neo4j驱动程序中的函数等效于py2neo中的 evaluate()函数?

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

将第二个代码的 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对象位于0x7f94cf7f31d0> ;;无法JSON序列化

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)

推荐答案

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

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.

这篇关于相当于py2neo函数的neo4j驱动程序函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆