-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort_review_data.py
64 lines (52 loc) · 1.7 KB
/
sort_review_data.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
from filter_review_data import (
get_negative_review_ids,
get_positive_review_ids,
load_english_reviews,
)
def get_useful_review_ids(english_review_dict, voted_up=None):
if voted_up is None:
review_ids = english_review_dict.keys()
elif voted_up:
review_ids = get_positive_review_ids(english_review_dict)
else:
review_ids = get_negative_review_ids(english_review_dict)
useful_review_ids = sorted(
review_ids,
key=lambda x: english_review_dict[x]['weighted_vote_score'],
reverse=True,
)
return useful_review_ids
def print_useful_reviews(english_review_dict, verbose=True):
useful_positive_review_ids = get_useful_review_ids(
english_review_dict,
voted_up=True,
)
useful_negative_review_ids = get_useful_review_ids(
english_review_dict,
voted_up=False,
)
the_most_useful_positive_review = english_review_dict[
useful_positive_review_ids[0]
]['review']
the_most_useful_negative_review = english_review_dict[
useful_negative_review_ids[0]
]['review']
print(
'The most useful positive review: {} characters'.format(
len(the_most_useful_positive_review),
),
)
print(
'The most useful negative review: {} characters'.format(
len(the_most_useful_negative_review),
),
)
if verbose:
print('\n[POSITIVE]\n----------\n')
print(the_most_useful_positive_review)
print('\n[NEGATIVE]\n----------\n')
print(the_most_useful_negative_review)
return
if __name__ == '__main__':
english_review_dict = load_english_reviews()
print_useful_reviews(english_review_dict)