运行 Cypher 语句
系统已为您提供一个包含人物和公司信息的图。图的模式(schema)已打印,包含 Person 与 Company 两类节点,以及这两类节点之间名为 WORKS_FOR 的关系。
已提供一条 Cypher 语句 cypher:它会查找名称属性等于参数 $name 的 (:Person) 节点,并返回其就职公司的 name 属性。
请在 graph 上执行该 Cypher 语句,找出 Jo Cornelissen 的任职公司。
本练习是课程的一部分
使用 LangChain 和 Neo4j 的 Graph RAG
练习说明
- 在
graph上执行保存在变量cypher中的 Cypher 语句。 - 从每个结果中提取
'company',以返回匹配到的公司名称。
交互式实操练习
通过完成这段示例代码来试试这个练习。
cypher = """MATCH (p:Person {name: $name})-[:WORKS_FOR]->(c:Company)
RETURN c.name AS company"""
# Execute the Cypher statement
result = graph.____(____, {"name": "Jo Cornelissen"})
# Extract the company
for row in result:
print(row[____])