github_mongoDB_dataprocess/prepare_for_doc2vec.py

39 lines
1.2 KiB
Python

from neo4j import GraphDatabase
driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "12345678"))
session = driver.session()
"""
path = './numpy_txt/issue/'
results = session.run('MATCH (n)-[r:belongsto]->(m:repository) where m.name="numpy_numpy" and n.state="closed" return n')
for res in results:
properties = res.get('n')._properties
with open(path+str(properties['name'])+'.txt','w',encoding='utf-8') as f:
try:
f.write(properties['title']+',')
except:
pass
try:
f.write(properties['body']+',')
except:
pass
try:
f.write(properties['labels'] + ',')
except:
pass
try:
f.write(properties['url'])
except:
pass
"""
path = './numpy_txt/comments/'
results = session.run("MATCH (a)-[r:commentson]->(b)-[:belongsto]->(c:repository) where c.name='numpy_numpy' and b.state='closed' return r,b")
for res in results:
with open(path + str(res.get('b')._properties['name']) + '.txt', 'a', encoding='utf-8') as f:
try:
f.write(res.get('r')._properties['body'] + ',')
except:
pass
driver.close()
# title、body、url、comment、labels