-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopRec.py
87 lines (71 loc) · 2.48 KB
/
topRec.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
import networkx as nx
import pandas as pd
import json
def authorListCurrent():
authList = pd.read_csv('authorListTrimmed.csv', delimiter=',')
authL = []
for j in authList.values:
if j[0] in authList.values and j != "App":
authL.append(j[0])
return authL
def authorNegativeSentimentTest(authL):
authList = pd.read_csv('negativeSentimentTest.csv', delimiter=',')
authNegative = []
count = 0
for j in authList.values:
if j[0] in authList.values and j != "App":
authNegative.append(j[0])
for i in authNegative:
if i in authL:
count += 1
total = len(authL)
difference = count/total
percentage = round(difference * 100, 2)
print("\nPercent of users who:")
print("\t- reviewed at least 5 apps\n\t- had at least 1 positive review\n\n\t",percentage,"%")
def topRecFunc(name):
roundedValue = 2
S = nx.read_gpickle("S_COMPLETE.gpickle")
appList = pd.read_csv('apps_names.csv', delimiter=',')
appL = []
for j in appList.values:
if j[0] in appList.values and j != "App":
appL.append(j[0])
recList = {}
recListOrdered = {}
if name in S.nodes:
for i in S[name]:
recList[i] = round(S[name][i]["weight"], roundedValue)
recKeyOrdered = sorted(recList, key=recList.get, reverse=True)
for i in recKeyOrdered:
recListOrdered[i] = recList[i]
authorDict = {name: recListOrdered}
authorJson = json.dumps(authorDict)
with open('currentAuthor.json', 'w', encoding='utf-8') as f:
f.write(authorJson)
return recListOrdered
else:
return {}
# Function is used to rank weighted edges from the recommendation bipartite graph
def topRecListFunc(name, authorList):
if len(authorList) > 0:
print("\nHere are the top 5 recommendations (or less) for", name)
count = 0
max = 5
for i in authorList:
count += 1
print(count, "-", i)
print("\tScore: ", authorList[i])
if count == max:
break
else:
print("\nNo recommendation available for this author.")
def topRecFullFunc():
authorListFullDict = {}
authList = authorListCurrent()
for i in authList:
authorListFullDict[i] = topRecFunc(i)
print(i)
authorListFullJson = json.dumps(authorListFullDict)
with open('authorRecListFull.json', 'w', encoding='utf-8') as f:
f.write(authorListFullJson)