forked from Sapphirine/Yelp_Recommendation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Review_functions.py
88 lines (74 loc) · 2.07 KB
/
Review_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
__author__ = 'Simons'
from main import*
from nltk.corpus import stopwords
from collections import Counter
from nltk import*
import types
import tfidf
def preProcessReviews(list):
porter = nltk.PorterStemmer()
stop = stopwords.words("english")
temp = []
i = 0;
G = []
for row in list:
token = nltk.word_tokenize(row[8])
'''print(token)'''
temp = ' '.join([a for a in token if a not in stop])
'''print(temp)'''
temp = nltk.word_tokenize(temp)
stem = [porter.stem(t) for t in temp]
'''print(stem)'''
row[8] = stem
row.append(stem)
for row in list:
print(row[9])
return list
'''words = ' '.join([a for a in reviews[i].split() if a not in stop])'''
def findStoreId(store_name):
store_id = 'null'
for row in store:
if(store_name == row[6]):
store_id = row[1]
if (store_id == 'null'):
print('Restaurant not found!')
else:
return store_id
def findStoreName(store_id):
store_name = 'null'
for row in store:
if(store_id == row[1]):
store_name = row[6]
if (store_name == 'null'):
print('Restaurant not found!')
else:
return store_name
def findUserReviews(user_id):
user_reviews=[]
for row in reviews:
if user_id == row[1]:
user_reviews.append(row[8])
return user_reviews
def findStoreReviews(store_id):
store_revies=[]
for row in reviews:
if store_id == row[2]:
store_reviews.append(row[8])
return store_reviews
def normalize(list):
length = len(list)
t = 0
for i in range(length):
if t < list[i]:
t = list[i]
for i in range(length):
list[i]=list[i]/t
return list
def compare (list1,list2,list3):
g = []
for rows in list1:
for rows in list2:
g.extend(tfidf(list1.rows[8],list2.rows[8],list3[rownumber]))
g = sorted(g,key=getKey)
g = normalize(g)
return g