【问题标题】:How to get the result using neo4j-driver functions as same as the result from evaluate() function in py2neo?如何使用 neo4j-driver 函数获得与 py2neo 中 evaluate() 函数的结果相同的结果?
【发布时间】:2021-02-27 07:46:50
【问题描述】:
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", auth=("neo4j","password"))

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

当第二个代码的 graph_response 的结果传递给下面的代码时,我收到一个错误

TypeError: 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_message(json.dumps(graph_response))
        return []

在行中传递时错误来了

dispatcher.utter_message(json.dumps(graph_response))

【问题讨论】:

标签: neo4j py2neo rasa neo4j-driver


【解决方案1】:

session.run 的输出是一个可以让您导航结果的对象,而不是结果本身。我强烈建议阅读驱动程序的手册和 API 文档,因为这些都在其中进行了描述。

根据my answer 到您的其他问题,要模拟evaluate,您只需导航到结果的第一条记录,然后返回该记录的第一个值。

【讨论】:

    猜你喜欢
    • 2021-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-17
    • 2015-04-09
    • 1970-01-01
    • 2021-05-07
    • 1970-01-01
    相关资源
    最近更新 更多