BUILD_GRAPH: ajout allignement entre neo4j et wikimedica

This commit is contained in:
Rémi Cérès 2019-11-27 01:27:31 -05:00
parent ea0be79129
commit 824b97dc2e
1 changed files with 22 additions and 0 deletions

View File

@ -1,12 +1,15 @@
#!/usr/bin/env python #!/usr/bin/env python
from fetch import wikidata from fetch import wikidata
from neo4j import GraphDatabase from neo4j import GraphDatabase
import json
NEO4J_URI = "bolt://localhost:7687" NEO4J_URI = "bolt://localhost:7687"
NEO4J_USR = "neo4j" NEO4J_USR = "neo4j"
NEO4J_PSW = "test" NEO4J_PSW = "test"
ALIGNEMENT_FILE_PATH = "data/alignment_result.json"
def define_link_from_type(link_id): 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 # Conection with Neo4j
driver = GraphDatabase.driver(NEO4J_URI, auth=(NEO4J_USR, NEO4J_PSW)) driver = GraphDatabase.driver(NEO4J_URI, auth=(NEO4J_USR, NEO4J_PSW))
create_graph() create_graph()
align_with_wikimedica()
# Close Neo4j connection # Close Neo4j connection
driver.close() driver.close()