Пример #1
0
CREATE (b:Business {id: {business_id}, name: {name}, lat:{latitude}, lon:{longitude},
	stars: {stars}, review_count: {review_count}})
'''

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})
Пример #2
0
CREATE (b:Business {id: {business_id}, name: {name}, lat:{latitude}, lon:{longitude},
	stars: {stars}, review_count: {review_count}})
'''

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, {