-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain2_proposed_pagerank.py
More file actions
67 lines (49 loc) · 1.28 KB
/
main2_proposed_pagerank.py
File metadata and controls
67 lines (49 loc) · 1.28 KB
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
from Question import Question
import pagerank
from common2 import *
graph = []
fin_pairs = open("questions/ques_pairs_with_groundtruth.txt")
lines = fin_pairs.readlines()
lines = ' '.join(lines)
fin_pairs.close()
edges_dict = {}
def addEdge(e):
if e not in edges_dict:
edges_dict[e] = True
graph.append(e)
counter = 0
for question_id in questions.keys():
counter += 1
if counter % 1000 == 0:
print counter
post = questions[question_id]
for non_best_user in post.non_best_answer_user_ids:
try:
for question in user_questions[non_best_user]:
addEdge((int(question_id), int(question)))
except KeyError:
pass
try:
for question in user_questions[post.best_answer_user_id]:
addEdge((int(question_id), int(question)))
except KeyError:
pass
# from hits_nx import hits_nx
# import networkx as nx
# G=nx.Graph()
# for edge in graph:
# G.add_edge(*edge)
# h,a=hits_nx(G)
# difficulty = dict()
# for i in questions.keys():
# if(h.has_key(int(i))):
# difficulty[int(i)] = h[int(i)]
# else:
# difficulty[int(i)]=0
# computeAccuracy(difficulty)
# ratings = pagerank.pagerank(graph, verbose = True)[0]
# computeAccuracy(ratings)
f = open('edges_basic.txt','w')
for edge in graph:
f.write(str(edge[0]) + " " + str(edge[1]) + "\n")
f.close()