def load_wiki_network(file_path="wikipedia_network.json"): # Read the JSON file with open(file_path, 'r', encoding='utf-8') as f: links_data = json.load(f) # Connect to Neo4j and load the data with driver.session() as session: # Create unique constraints if they don't exist session.run("CREATE CONSTRAINT page_name IF NOT EXISTS FOR (p:Page) REQUIRE p.name IS UNIQUE") # Create nodes and relationships for link in links_data: # Create or merge nodes and relationship session.run( """ MERGE (from:Page {name: $from}) MERGE (to:Page {name: $to}) CREATE (from)-[:REFERENCES {context: $context}]->(to) """, parameters={"from": link["from"], "to": link["to"], "context": link["context"]} ) print(f"Successfully loaded {len(links_data)} relationships into Neo4j")