【问题标题】:neo4j driver functions equivalent to py2neo functionsneo4j 驱动函数等价于 py2neo 函数
【发布时间】:2020-11-18 23:50:28
【问题描述】:
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_custom_message(graph_response)
        return []

在行中传递时错误来了

dispatcher.utter_custom_message(graph_response)

【问题讨论】:

    标签: python graph-databases py2neo rasa neo4j-driver


    【解决方案1】:

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

    【讨论】:

    • 你能告诉我在使用函数run时如何从第一条记录中获取第一个值吗?
    猜你喜欢
    • 2021-09-25
    • 2011-06-08
    • 2011-11-10
    • 2011-10-13
    • 2011-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多