From 824b97dc2ea3ea9a6e17bd765e589d6cd8e5b443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20C=C3=A9r=C3=A8s?= Date: Wed, 27 Nov 2019 01:27:31 -0500 Subject: [PATCH] BUILD_GRAPH: ajout allignement entre neo4j et wikimedica --- data/build_graph.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/data/build_graph.py b/data/build_graph.py index a3e794e..7276de4 100755 --- a/data/build_graph.py +++ b/data/build_graph.py @@ -1,12 +1,15 @@ #!/usr/bin/env python from fetch import wikidata from neo4j import GraphDatabase +import json NEO4J_URI = "bolt://localhost:7687" NEO4J_USR = "neo4j" NEO4J_PSW = "test" +ALIGNEMENT_FILE_PATH = "data/alignment_result.json" + def define_link_from_type(link_id): @@ -88,10 +91,29 @@ def create_graph(): +def align_with_wikimedica(): + """ + Align neo4j graph and Wikidata + """ + with open(ALIGNEMENT_FILE_PATH, "r") as align_file: + align = json.loads(align_file.read()) + + for entity in align: + if 'wikidata_id' in entity: + with driver.session() as session: + session.run( + "MATCH (d {id:$wikidata_id})" + "SET d.wikimedia_id = $wikimedica_uri", + wikidata_id=entity['wikidata_id'], + wikimedica_uri=entity['wikimedica_uri'], + ) + + # Conection with Neo4j driver = GraphDatabase.driver(NEO4J_URI, auth=(NEO4J_USR, NEO4J_PSW)) create_graph() +align_with_wikimedica() # Close Neo4j connection driver.close()