Neo4j Graph Database Homework

profilezfuson
Neo4j_CaseStudyYelp_2021DataImport.ppt

*

Case Study
Yelp_2021 Data Import

Summer, 2021

Dar-jen Chang

Computer Science and Engineering

University of Louisville

*

*

Sources and References

[1] Yelp Datasets Download
https://www.yelp.com/dataset/download

[2] APOC 4.1 User’s Guide
https://neo4j.com/labs/apoc/4.1/

*

Yelp 2021 Business.json Import
Settings

Add these lines:

apoc.import.file.enabled=true

apoc.export.file.enabled=true

and

Modifying this line (make sure your computer has enough RAM):

dbms.memory.heap.max_size = 5G

*

Yelp 2021 business.json Import
Create Constraints and Indexes

// Define graph schema (index/constraints)

CALL apoc.schema.assert(

{Category:['name']},

{Business:['id'],User:['id'],Review:['id']});

*

Yelp 2021 Business.json Import
Explore business.json

CALL apoc.load.json('file:///business.json') YIELD value

RETURN count(value)

160,585

*

{

"hours": {

"Monday": "11:0-23:0",

"Thursday": "11:0-23:0",

"Friday": "11:0-23:0",

"Sunday": "11:0-23:0",

"Wednesday": "11:0-23:0",

"Tuesday": "11:0-23:0",

"Saturday": "11:0-23:0"

},

"address": "921 Pearl St",

"city": "Boulder",

"is_open": 1,

"latitude": 40.0175444,

"review_count": 86,

"stars": 4.0,

"name": "Oskar Blues Taproom",

Yelp 2021 Business.json Import
Explore business.json

CALL apoc.load.json('file:///business.json') YIELD value

RETURN value limit 1

*

"attributes": {

"BikeParking": "True",

"BusinessAcceptsCreditCards": "True",

"RestaurantsDelivery": "None",

"BusinessAcceptsBitcoin": "False",

"BusinessParking": "{'garage': False, 'street': True, 'validated': False, 'lot': False, 'valet': False}",

"RestaurantsGoodForGroups": "True",

"NoiseLevel": "u'average'",

"RestaurantsTableService": "True",

"RestaurantsPriceRange2": "2",

"Alcohol": "'beer_and_wine'",

"RestaurantsReservations": "False",

"WheelchairAccessible": "True",

"RestaurantsTakeOut": "True",

"Caters": "True",

"HappyHour": "True",

"RestaurantsAttire": "'casual'",

"HasTV": "True",

"Ambience": "{'touristy': False, 'hipster': False, 'romantic': False, 'divey': False, 'intimate': False, 'trendy': False, 'upscale': False, 'classy': False, 'casual': True}",

"WiFi": "u'free'",

"DogsAllowed": "False",

"OutdoorSeating": "True",

"GoodForMeal": "{'dessert': False, 'latenight': False, 'lunch': False, 'dinner': False, 'brunch': False, 'breakfast': False}"

},

Yelp 2021 Business.json Import
Explore business.json

*

"state": "CO",

"categories": "Gastropubs, Food, Beer Gardens, Restaurants, Bars, American (Traditional), Beer Bar, Nightlife, Breweries",

"postal_code": "80302",

"business_id": "6iYb2HFDywm3zjuRg0shjw",

"longitude": -105.2833481

}

Yelp 2021 Business.json Import
Explore business.json

*

Yelp 2021 Business.json Import
Import business.json

CALL apoc.periodic.iterate("

CALL apoc.load.json('file:///business.json') YIELD value

MERGE (b:Business{id:value.business_id})

SET b += apoc.map.clean(value, ['attributes','hours','business_id','categories'],[])

WITH b, split(value.categories, ',') as categories

UNWIND categories as category

MERGE (c:Category{id:trim(category)})

MERGE (b)-[:IN_CATEGORY]->(c)",

"",

{batchSize: 10000, iterateList: true});

Notice the function, apoc.map.clean(i_map, list_keys, list_values), removes the list_keys from the i_map.

*

Yelp 2021 Business.json Import
Import business.json

CALL apoc.load.json('file:///business.json') YIELD value

With value limit 10000

MERGE (b:Business{id:value.business_id})

SET b += apoc.map.clean(value, ['attributes','hours','business_id','categories'],[])

WITH b, split(value.categories, ',') as categories

UNWIND categories as category

MERGE (c:Category{id:trim(category)})

MERGE (b)-[:IN_CATEGORY]->(c)

*

Yelp 2021 Business.json Import
Test run

match (b:Business), (c:Category)

return count(distinct b) as number_of_businesses,
count(distinct c) as number_of_catagories

*

Yelp 2021 Business.json Import
Test run

match (b:Business)

with count(b) as number_of_businesses

match (c:Category)

return number_of_businesses, count(c) as number_of_catagories

*

Yelp 2021 Business.json Import
Test run

match (b:Business)-[:IN_CATEGORY]->(c:Category)

with b limit 2

match (b)-[:IN_CATEGORY]->(c:Category)

return b, c

*

Yelp 2021 Business.json Import
Test run

match (b:Business)-[:IN_CATEGORY]->(c:Category)

where b.name = 'Drink Well'

return b, c

*

Yelp 2021 Business.json Import
Test run

match (b:Business)

return min(apoc.node.degree(b,'IN_CATEGORY')) as min_degree,

max(apoc.node.degree(b,'IN_CATEGORY')) as max_degree,

avg(apoc.node.degree(b,'IN_CATEGORY')) as mean_degree,

stDev(apoc.node.degree(b,'IN_CATEGORY')) as std_degree

*

Yelp 2021 Business.json Import
Test run

match (b:Business)

with b.id as id, apoc.node.degree(b, 'IN_CATEGORY') as degree

where degree = 0

return id

*

Yelp 2021 Business.json Import
Test run

optional match (b:Business)-[]->(c:Category)

where b.id = "VD_mB3i4GG-Ra-sFqlxzeA"

return b, c

*

Yelp 2021 Business.json Import
Test run

match (b:Business)

with b, apoc.node.degree(b, 'IN_CATEGORY') as degree

where degree = 37

return b.id, b.name, b.city