BUILD_GRAPH: ajout allignement entre neo4j et wikimedica
This commit is contained in:
parent
ea0be79129
commit
824b97dc2e
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue