def create_directory_children(dirs, parent): '''Create the following relationship: (p:Directory)<-[:PARENT]-(d:Directory) where dirs is a list of strings and parent is a py2neo node.''' batch = WriteBatch(graph_db) for d in dirs: dir_node = batch.create({'name': d, '_id': uuid.uuid4().hex}) batch.add_labels(dir_node, "Directory") batch.create(rel(dir_node, "PARENT", parent)) batch.run()
def create_file_children(files, parent, root_path): '''Create (p:Directory)<-{:PARENT]-(f:File) for all files to the given parent. Also stores the file's contents in the content property.''' batch = WriteBatch(graph_db) for f in files: file_content = get_file_content(f, root_path) file_node = batch.create({'name': f, '_id': uuid.uuid4().hex, 'content': file_content}) batch.add_labels(file_node, 'File') batch.create(rel(file_node, "PARENT", parent)) batch.run()
merge_category_query = ''' MATCH (b:Business {id: {business_id}}) MERGE (c:Category {name: {category}}) CREATE UNIQUE (c)<-[:IS_IN]-(b) ''' print "Beginning business batch" with open('data/yelp_academic_dataset_business.json', 'r') as f: business_batch = WriteBatch(db) count = 0 for b in (json.loads(l) for l in f): business_batch.append_cypher(create_business_query, b) count += 1 if count >= 10000: business_batch.run() business_batch.clear() count = 0 if count > 0: business_batch.run() print "Beginning category batch" with open('data/yelp_academic_dataset_business.json', 'r') as f: category_batch = WriteBatch(db) count = 0 for b in (json.loads(l) for l in f): for c in b['categories']: category_batch.append_cypher(merge_category_query, {'business_id': b['business_id'], 'category': c}) count += 1 if count >= 10000: category_batch.run()
merge_category_query = ''' MATCH (b:Business {id: {business_id}}) MERGE (c:Category {name: {category}}) CREATE UNIQUE (c)<-[:IS_IN]-(b) ''' print "Beginning business batch" with open('data/yelp_academic_dataset_business.json', 'r') as f: business_batch = WriteBatch(db) count = 0 for b in (json.loads(l) for l in f): business_batch.append_cypher(create_business_query, b) count += 1 if count >= 10000: business_batch.run() business_batch.clear() count = 0 if count > 0: business_batch.run() print "Beginning category batch" with open('data/yelp_academic_dataset_business.json', 'r') as f: category_batch = WriteBatch(db) count = 0 for b in (json.loads(l) for l in f): for c in b['categories']: category_batch.append_cypher(merge_category_query, { 'business_id': b['business_id'], 'category': c })