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

当它在行中传递时错误来了

dispatcher.utter_message(json.dumps(graph_response))
4

1 回答 1

0

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

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

于 2020-11-16T21:17:50.653 回答