Answered step by step
Verified Expert Solution
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 cleanStrSQLs:
return sreplacereplace
def getAttributesattributes:
L
for attribute value in listattributesitems:
if isinstancevalue dict:
L getAttributesvalue
else:
Lappendattributevalue
return L
def parseBusinessData:
printParsing businesses..."
#read the JSON file
with openyelpbusiness.JSON',r as f:
outfile openyelpbusiness.txtw
line freadline
countline
#read each JSON abject and extract data
while line:
data json.loadsline
business databusinessid #business id
businessstr cleanStrSQLdataname
cleanStrSQLdataaddress
cleanStrSQLdatacity
datastate
datapostalcode'
strdatalatitude
strdatalongitude
examples from each file:
yelpuser:
averagestars": "complimentcool": "complimentcute": "complimentfunny": "complimenthot": "complimentlist": "complimentmore": "complimentnote": "complimentphotos": "complimentplain": "complimentprofile": "complimentwriter": "cool": "elite": "fans": "friends": UsnBHWdTSlHNXIlXA "pnfVIBUhvCQXKQXIw", "jVYzrVblDFSuLGHttZSA", ZbpqYZiBHXdoUNkiw", AqrflOeitNowtigzjcNkCVeKKONeQtgdrMKNHWavsgufpLtvgKViyfmVqnzIitRTIlg", "rUVFUhjixMjNBpcqSXg "yrGIgkeaWyeewLNvKHQVdATdvvuVVgnYCpzfw "ebCpHKuxyDenoXbbgRJrGgtBXkpXoEHMhSqXg "sdpIzsTCZBdAgAjzQHGicjWehA "AvCXQAElcGAAnWrauEg", JlkHKBnHKdKTplsAFAwAGMctcxTjPsvmUrtyQbKxdvnKpmWjMzlmBvpXwVVMSJyUkhyfCxNsA", roOGjjCSKnFOJinKjg", KthOnvZPFYiCnTRw "pRBzWnFzaCEtqhYyJZTDQ "nwESZeKzXtfKkOuRdIQ", WNZfkLDBspueoGSUOMAqA", uUfQWadrHxMPVmykQ "XiLxIJThWsExdIeSPsg", YLBTbwOgBmdBIiDCAjGbjflEIQJcfaAFKQnxWrhFhyXwwjrEkQXuQkGrVVqLIKtVEmDuQ", oSTsEtfvDIgJZuxA", xyoEggBLpIEKMnhDQrCxtbtoOJUsvdOeqYYgnkNdofJxekchVCvAKzHRsFwrySbFogkkkGA", pBzBgtCTNPNUPfgPDIAPUQaMADaNZoQZjOw", "FkfpHzqoDRChwOYhANPnQ "CaQyzzajGKkNSbXiwbrQOjBfnXWGkAAg "funny": "name": "Andrea", "reviewcount": "useful": "userid: omZiponkpRqUNapVPiRg", "yelpingsince":
yelpcheckin:
time: Friday: :: :: :: :: :: :: :: "Thursday": :: :: :: :: :: :: "Wednesday": :: :: :: :: :: :: "Sunday": :: :: :: :: :: :: :: "Saturday": :: :: :: :: :: :: :: :: :: :: "Tuesday": :: :: :: :: :: "Monday": :: :: :: "businessid: "dwQEZBFenGdihLLfWeexA"
yelpreview.json:
reviewid:ClgrKJdqiMvSKJBJwQ"userid:TMGSNHBCWgofZQBtng"businessid:"dwQEZBFenGdihLLfWeexA","stars":"date":""text":"I've been here at least 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":"funny":"cool":
yelpbusiness.json:
businessid: xmYpzNvZKEzuNXEqeVw
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started