pythonリンクneo 4 jインポートデータインスタンス
データループインポートneo 4 j
import json
from py2neo import Graph, Node, Relationship
## py2neo neo4j
class ImportData:
def __init__(self):
self.input_path = './ - /map.json'
def load_data(self, path):
## json
f_input = open(path, 'r', encoding='utf-8', errors='ignore')
data = json.loads(f_input.read())["data"]
f_input.close()
return data
def link_import(self, data):
""" neo4j,
"""
#
# graph = Graph("http://192.168.0.21:12273", username="neo4j", password='test')
graph = Graph("http://localhost:7474", username="neo4j", password='123')
for content in data:
keywords = content["keywords"] #
name = content["name"] #
labels = content["labels"][0] # , labels
# # * , create
# m = 'match (n{name:"'+name+'"}) return n'
# g_m = graph.run(m).data()
# if len(g_m) == 0:
# m1 = 'merge (n:'+labels+'{name:"'+name+'"}) return n'
# g_m1 = graph.run(m1)
# for key in keywords:
# # * , create
# m2 = 'match (n{name:"'+key+'"}) return n'
# g_m2 = graph.run(m2).data()
# if len(g_m2) == 0:
# m3 = 'merge (n: {name:"'+key+'"}) return n'
# g_m3 = graph.run(m3)
# # ( * ) , create
# r1 = 'match (n{name:"'+name+'"}),(m{name:"'+key+'"}) match (n)-[r: ]->(m) return r'
# g_r1 = graph.run(r1).data()
# if len(g_r1) == 0:
# r2 = 'match (n{name:"'+name+'"}),(m{name:"'+key+'"}) create (n)-[r: ]->(m) return n, r, m'
# g_r2 = graph.run(r2)
print(keywords, name, labels)
if __name__=='__main__':
ImportData = ImportData()
input_path = ImportData.input_path
data = ImportData.load_data(input_path)
#print(data)
res = ImportData.link_import(data)