Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

use SQL to analyse the data from JSON files. used to parse: def cleanStr 4 SQL ( s ) : return s . replace (

use SQL to analyse the data from JSON files.
used to parse:
def cleanStr4SQL(s):
return s.replace("'","''").replace("
","")
def getAttributes(attributes):
L =[]
for (attribute, value) in list(attributes.items()):
if isinstance(value, dict):
L += getAttributes(value)
else:
L.append((attribute,value))
return L
def parseBusinessData():
print("Parsing businesses...")
#read the JSON file
with open('.//yelp_business.JSON','r') as f:
outfile = open('.//yelp_business.txt','w')
line = f.readline()
count_line =0
#read each JSON abject and extract data
while line:
data = json.loads(line)
business = data['business_id'] #business id
business_str ="'"+ cleanStr4SQL(data['name'])+"',"+\
"'"+ cleanStr4SQL(data['address'])+"',"+\
"'"+ cleanStr4SQL(data['city'])+"',"+\
"'"+ data['state']+"',"+\
"'"+ data['postal_code']+"',"+\
str(data['latitude'])+","+\
str(data['longitude'])+",
examples from each file:
yelp_user:
{"average_stars": 3.94, "compliment_cool": 1556, "compliment_cute": 211, "compliment_funny": 1556, "compliment_hot": 1285, "compliment_list": 101, "compliment_more": 134, "compliment_note": 1295, "compliment_photos": 162, "compliment_plain": 2134, "compliment_profile": 74, "compliment_writer": 402, "cool": 40110, "elite": [2014,2017,2011,2012,2015,2009,2013,2007,2016,2006,2010,2008], "fans": 835, "friends": ["U_sn0B-HWdTSlHNXIl_4XA", "pnfVIB7UhvCQ7X2K0Q2XIw", "jVYzrVblDFSuL3GHtt8ZSA", "Z7bpqY89ZiBHXdo7UN1kiw", "8Aqr35f254lOeitNowt7ig","zjcN27kCVeK8K2ONe9Qt4g","8drMKNHWavs2g6uf0pLtvg","_K2ViyfmVq6nzIitR0TIlg", "rUV1FUhji5xMjNBpcq5SXg", "yrGIgk5eaWy-eewLNv4KHQ","3Vd_ATdvvuVVgn_YCpz8fw", "ebC_pH92K4uxyDenoXb5bg","RJrGgtBXkpX2oEHM4hSqXg", "sdpIz4-s15T239CZ4Bd6Ag","A0j21z2Q1HGic7jW6e9h7A", "AvC5XQAElcGAAn_Wr5auEg", "JlkHKBnHKdK8Tpls0AF5Aw","8AG5MctcxTjP4svmUrt0yQ","bKxdvn7KpmWjMzlmBvp-Xw","VVMS74JyUk2h53yfC-xNsA", "-ro7OG3jjCSKnF6OJinKjg", "K7thO1n-vZ9PFYiC7nTR2w", "pRBzWnFzaCEtqhYyJ2ZTDQ", "nwESZ8e-KzXt2fKkOuRdIQ", "WNZfkL4DBspueoGSUOMAqA", "uU6fQWadr7Hx_MP0Vmy3kQ", "XiLxIJThWsE0x4d0IeSPsg", "Y9LBTbwO4g0BmdBIi0D3CA","jGbj8fl575EIQJcfaA1FKQ","nxWrhF_hyX0wwjrEkQX8uQ","670k6Gr6V4VqLIKtVEmDuQ", "o5STsEtfvD1Ig0J7Z-1uxA", "x13yoEggBL0pIE7-KMnhDQ","rCx7tb3toOJUsvdOeqYY0g","nkN_do3fJ9xekchVC-v68A","KzHRsFwryS7b5Fog8kkkGA", "_pBzBgtCTN9PNUPfgPDI8A","PU5QaMADa6N_9ZoQ04ZjOw", "FkfpHzqoDRChwOYhA6NPnQ", "CaQy-zz10ajG7KkNSbXi5w","brQ7OjB6f9nXWGk45A9A3g"], "funny": 10882, "name": "Andrea", "review_count": 2559, "useful": 83681, "user_id": "om5ZiponkpRqUNa3pVPiRg", "yelping_since": "2006-01-18"}
yelp_checkin:
{"time": {"Friday": {"20:00": 2,"19:00": 1,"22:00": 10,"21:00": 5,"23:00": 14,"0:00": 2,"18:00": 2}, "Thursday": {"23:00": 1,"0:00": 1,"19:00": 1,"18:00": 1,"16:00": 2,"22:00": 2}, "Wednesday": {"17:00": 2,"23:00": 3,"16:00": 1,"22:00": 1,"19:00": 1,"21:00": 1}, "Sunday": {"16:00": 2,"17:00": 2,"19:00": 1,"22:00": 4,"21:00": 4,"0:00": 3,"1:00": 2}, "Saturday": {"21:00": 4,"20:00": 3,"23:00": 10,"22:00": 7,"18:00": 1,"15:00": 2,"16:00": 1,"17:00": 1,"0:00": 8,"1:00": 1}, "Tuesday": {"19:00": 1,"17:00": 1,"1:00": 2,"21:00": 1,"23:00": 3}, "Monday": {"18:00": 2,"23:00": 1,"22:00": 2}}, "business_id": "dwQEZBFen2GdihLLfWeexA"}
yelp_review.json:
{"review_id":"ClgrKJ6dqiM7vSKJBJ2w6Q","user_id":"T5MGS0NHBCWgofZ6Q6Btng","business_id":"dwQEZBFen2GdihLLfWeexA","stars":4,"date":"2013-06-03","text":"I've been here at least 5 times now and each time is better than the last. I Iove what they have done to improve the building and add outdoor dining. Service is always good here and on par with other top places in Mentor. I really suggest the chicken soup on a cold day it's very yummy! Everything I've had on the menu has been great.","useful":0,"funny":0,"cool":0}
yelp_business.json:
{"business_id": "xmY0pzNvZKEzuN0XEqeV5w"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David J. Auer David M. Kroenke

13th Edition

B01366W6DS, 978-0133058352

More Books

Students also viewed these Databases questions