Exemple #1
0
	def testReview(self, reviewJSON):
		review = f.getJson(reviewJSON)
		userID = f.getUser(review)
		businessID = f.getBusiness(review)
		rate = f.getRate(review)
		prediction = self.predictKNN(userID, businessID)
		return (userID, rate == prediction, rate, prediction)
Exemple #2
0
	def __init__(self, numNeighbors, reviewFilePath, featureType):			
		self.numNeighbors = numNeighbors
		self.featureType = featureType
		self.busiID2Busi = {}
		self.userID2User = {}
		self.userCount=0
		self.businessCount=0
		reviews = open(reviewFilePath, 'r')
		for r in reviews:
			reviewJson = f.getJson(r)
			userID = f.getUser(reviewJson)
			businessID = f.getBusiness(reviewJson)		
			text = f.getText(reviewJson)
			rate = f.getRate(reviewJson)
			if businessID not in self.busiID2Busi.keys():
				busiObj = Business(businessID, numNeighbors)
				self.busiID2Busi[businessID]=busiObj
				self.businessCount+=1
			else:
				busiObj = self.busiID2Busi[businessID]
			if userID not in self.userID2User.keys():
				userObj = User(userID)
				self.userCount+=1
				self.userID2User[userID]=userObj
			else:
				userObj = self.userID2User[userID]
			userObj.addReview(text)
			busiObj.addUser(userObj,rate)
		reviews.close()
		for b in self.busiID2Busi.values():
			b.trainKNN(self.featureType)