133 lines
8.1 KiB
Python
133 lines
8.1 KiB
Python
|
|
|
|
from neo4j import GraphDatabase
|
|
|
|
driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "12345678"))
|
|
session = driver.session()
|
|
|
|
# # user
|
|
# for i in range(1,6):
|
|
# session.run("CALL apoc.load.json('file:C:/Users/zhou/Desktop/github_mongoDB/json/entity/user"+str(i)+".json') YIELD value as node"
|
|
# "\nCREATE (:user{name:node.login,id:node.id})")
|
|
# print('user',i,'finished')
|
|
# # repo
|
|
# session.run("CALL apoc.load.json('file:C:/Users/zhou/Desktop/github_mongoDB/json/entity/repo.json') YIELD value as node"
|
|
# "\nCREATE (:repository{name:node.name})")
|
|
# print('repo finished')
|
|
# #issue
|
|
# for i in range(1,92):
|
|
# session.run("CALL apoc.load.json('file:C:/Users/zhou/Desktop/github_mongoDB/json/entity/issue"+str(i)+".json') YIELD value as node"
|
|
# "\nCREATE (:issue{name:node.name,url:node.url,number:node.number,title:node.title,state:node.state,locked:node.locked,"
|
|
# "created_at:node.created_at,updated_at:node.updated_at,closed_at:node.closed_at,author_association:node.author_association,"
|
|
# "active_lock_reason:node.active_lock_reason,body:node.body,state_reason:node.state_reason,"
|
|
# "reactions:apoc.convert.toJson(node.reactions)})")
|
|
# print('issue', i, 'finished')
|
|
# #pr
|
|
# for i in range(1,133):
|
|
# session.run("CALL apoc.load.json('file:C:/Users/zhou/Desktop/github_mongoDB/json/entity/pr"+str(i)+".json') YIELD value as node"
|
|
# "\nCREATE (:pr{name:node.name,url:node.url,number:node.number,title:node.title,state:node.state,locked:node.locked,"
|
|
# "created_at:node.created_at,updated_at:node.updated_at,closed_at:node.closed_at,author_association:node.author_association,"
|
|
# "active_lock_reason:node.active_lock_reason,body:node.body,state_reason:node.state_reason,"
|
|
# "reactions:apoc.convert.toJson(node.reactions),merged_at:node.pull_request.merged_at})")
|
|
# print('pr', i, 'finished')
|
|
# #assigns
|
|
# for i in range(1,9):
|
|
# session.run("CALL apoc.load.json('file:C:/Users/zhou/Desktop/github_mongoDB/json/relationship/assigned"+str(i)+".json') YIELD value as rela"#文件名
|
|
# "\nCREATE (:relation{from:rela.assigner,to:rela.issue,time:rela.time})")#属性选择
|
|
# session.run("MATCH (n:user),(m:relation),(s:issue|pr) where n.id=m.from and s.name=m.to" # 对应关系
|
|
# "\nCREATE (n)-[:assigns{time:m.time}]->(s)") # 属性和名称
|
|
# session.run("MATCH (n:relation) DELETE n")
|
|
# print('assigns',i,'finished')#输出
|
|
# #assignedto
|
|
# for i in range(1,9):
|
|
# session.run("CALL apoc.load.json('file:C:/Users/zhou/Desktop/github_mongoDB/json/relationship/assigned"+str(i)+".json') YIELD value as rela"
|
|
# "\nCREATE (:relation{from:rela.assignee,to:rela.issue,time:rela.time})")
|
|
# session.run("MATCH (n),(m:relation),(s:issue|pr) where n.id=m.from and s.name=m.to"
|
|
# "\nCREATE (n)-[:assignedto{time:m.time}]->(s)")
|
|
# session.run("MATCH (n:relation) DELETE n")
|
|
# print('assignedto',i,'finished')
|
|
# #belongsto
|
|
# for i in range(1,29):
|
|
# session.run("CALL apoc.load.json('file:C:/Users/zhou/Desktop/github_mongoDB/json/relationship/belongto"+str(i)+".json') YIELD value as rela"
|
|
# "\nCREATE (:relation{from:rela.from,to:rela.to})")
|
|
# session.run("MATCH (n:issue|pr),(m:relation),(s:repository) where n.name=m.from and s.name=m.to"
|
|
# "\nCREATE (n)-[:belongsto]->(s)")
|
|
# session.run("MATCH (n:relation) DELETE n")
|
|
# print('belongsto',i,'finished')
|
|
# #closes
|
|
# for i in range(1,28):
|
|
# session.run("CALL apoc.load.json('file:C:/Users/zhou/Desktop/github_mongoDB/json/relationship/closed"+str(i)+".json') YIELD value as rela"
|
|
# "\nCREATE (:relation{from:rela.from,time:rela.time,to:rela.to})")
|
|
# session.run("MATCH (n),(m:relation),(s:issue|pr) where n.id=m.from and s.name=m.to"
|
|
# "\nCREATE (n)-[:closes{time:m.time}]->(s)")
|
|
# session.run("MATCH (n:relation) DELETE n")
|
|
# print('closes',i,'finished')
|
|
# # #commentson (1,161)(162,396)(400,402)
|
|
# num = [400,401]
|
|
# for i in range(1,396):
|
|
# if not i == 161:
|
|
# num.append(i)
|
|
# for i in num:
|
|
# session.run("CALL apoc.load.json('file:C:/Users/zhou/Desktop/github_mongoDB/json/relationship/commented"+str(i)+".json') YIELD value as rela"
|
|
# "\nCREATE (:relation{from:rela.from,time:rela.time,to:rela.to,body:rela.body,association:rela.author_association})")
|
|
# session.run("MATCH (n),(m:relation),(s) where n.id=m.from and s.name=m.to"
|
|
# "\nCREATE (n)-[:commentson{time:m.time,body:m.body,author_association:m.association}]->(s)")
|
|
# session.run("MATCH (n:relation) DELETE n")
|
|
# print('commentson',i,'finished')
|
|
# #cross-references
|
|
# for i in range(1,2):
|
|
# session.run("CALL apoc.load.json('file:C:/Users/zhou/Desktop/github_mongoDB/json/relationship/link"+str(i)+".json') YIELD value as rela"
|
|
# "\nCREATE (:relation{from:rela.to,time:rela.time,to:rela.from,actor:rela.actor})")
|
|
# session.run("MATCH (n),(m:relation),(s) where n.name=m.from and s.name=m.to"
|
|
# "\nCREATE (n)-[:crossreferences{time:m.time,person:m.actor}]->(s)")
|
|
# session.run("MATCH (n:relation) DELETE n")
|
|
# print('cross-references',i,'finished')
|
|
# #dependson
|
|
# for i in range(1,2):
|
|
# session.run("CALL apoc.load.json('file:C:/Users/zhou/Desktop/github_mongoDB/json/relationship/depend"+str(i)+".json') YIELD value as rela"
|
|
# "\nCREATE (:relation{from:rela.from,to:rela.to})")
|
|
# session.run("MATCH (n),(m:relation),(s) where n.name=m.from and s.name=m.to"
|
|
# "\nCREATE (n)-[:dependson]->(s)")
|
|
# session.run("MATCH (n:relation) DELETE n")
|
|
# print('dependson',i,'finished')
|
|
# # forks
|
|
# session.run("CALL apoc.load.json('file:C:/Users/zhou/Desktop/github_mongoDB/json/relationship/fork.json') YIELD value as rela"
|
|
# "\nCREATE (:relation{from:rela.from,to:rela.to})")
|
|
# session.run("MATCH (n),(m:relation),(s) where n.name=m.from and s.name=m.to"
|
|
# "\nCREATE (n)-[:forks]->(s)")
|
|
# session.run("MATCH (n:relation) DELETE n")
|
|
# print('forks finished')
|
|
# #labels
|
|
# for i in range(1,46):
|
|
# session.run("CALL apoc.load.json('file:C:/Users/zhou/Desktop/github_mongoDB/json/relationship/labeled"+str(i)+".json') YIELD value as rela"
|
|
# "\nCREATE (:relation{from:rela.from,to:rela.to,time:rela.time,label:rela.label})")
|
|
# session.run("MATCH (n),(m:relation),(s) where n.id=m.from and s.name=m.to"
|
|
# "\nCREATE (n)-[:labels{time:m.time,label:m.label}]->(s)")
|
|
# session.run("MATCH (n:relation) DELETE n")
|
|
# print('labels',i,'finished')
|
|
# #links
|
|
# for i in range(1,2):
|
|
# session.run("CALL apoc.load.json('file:C:/Users/zhou/Desktop/github_mongoDB/json/relationship/link"+str(i)+".json') YIELD value as rela"
|
|
# "\nCREATE (:relation{from:rela.actor,to:rela.from,time:rela.time})"
|
|
# "\nCREATE (:relation{from:rela.actor,to:rela.to,time:rela.time})")
|
|
# session.run("MATCH (n),(m:relation),(s) where n.id=m.from and s.name=m.to"
|
|
# "\nCREATE (n)-[:links{time:m.time}]->(s)")
|
|
# session.run("MATCH (n:relation) DELETE n")
|
|
# print('links',i,'finished')
|
|
# #mentionedin
|
|
# for i in range(1,40):
|
|
# session.run("CALL apoc.load.json('file:C:/Users/zhou/Desktop/github_mongoDB/json/relationship/mentionedin"+str(i)+".json') YIELD value as rela"
|
|
# "\nCREATE (:relation{from:rela.from,to:rela.to,time:rela.time})")
|
|
# session.run("MATCH (n),(m:relation),(s) where n.id=m.from and s.name=m.to"
|
|
# "\nCREATE (n)-[:mentionedin{time:m.time}]->(s)")
|
|
# session.run("MATCH (n:relation) DELETE n")
|
|
# print('mentionedin',i,'finished')
|
|
#opens
|
|
for i in range(1,29):
|
|
session.run("CALL apoc.load.json('file:C:/Users/zhou/Desktop/github_mongoDB/json/relationship/opened"+str(i)+".json') YIELD value as rela"
|
|
"\nCREATE (:relation{from:rela.from,to:rela.to,time:rela.time})")
|
|
session.run("MATCH (n),(m:relation),(s) where n.id=m.from and s.name=m.to"
|
|
"\nCREATE (n)-[:opens{time:m.time}]->(s)")
|
|
session.run("MATCH (n:relation) DELETE n")
|
|
print('opens',i,'finished')
|
|
driver.close() |