執行 Cypher 陳述式
系統已提供一個包含人員與公司資料的圖形。已為你列印圖形結構,顯示 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[____])