def buildgraph(self, postId): cmnts = getCommentInPost(postId, False) for cmnt in cmnts: #replace native fb comment Id by local comment index in cmntIdMap cmntIdx = len(self.cmntIdMap) if cmntIdx >= GRAPH_SIZE: break self.cmntIdMap.append(cmnt['id']) #put comment into comment_window self.cmnts_window.append({'message':cmnt['message'], 'evicted':False}) #put the commentor into user_window cmnterId = cmnt['from']['id'] if cmnterId in self.users_window: self.users_window[cmnterId].append(cmntIdx) else: self.users_window[cmnterId] = [cmntIdx] #get the likes and fill into like_window likes= cmnt.get('likes',{}).get('data',[]) for l in likes: if l['id'] in self.likes_window: self.likes_window[l['id']].append(cmntIdx) else: self.likes_window[l['id']]= [cmntIdx] #voc window here text = cmnt['message'].lower() words = text.split() voc_link ={}#cmntIdx:count count the common word between current comment and previous ones for w in words: if w not in self.skipWords: if w in self.voc_window: for idx in self.voc_window[w]: voc_link[idx] = voc_link.get(idx, 0) + 1 self.voc_window[w].append(cmntIdx) else: self.voc_window[w] = [cmntIdx] #build the graph #using like info if cmnterId in self.likes_window: for likedIdx in self.likes_window[cmnterId]: self.prg[likedIdx, cmntIdx] += 1 #using voc info for idx, commonwordcount in voc_link.items(): #do filtering here self.prg[idx, cmntIdx] += 1 #end while eig ,eigv = eigs(self.prg) print >> builder.logwriter, 'max eigen value', max(eig), 'eigen size:', len(eig),'\n'
def postDetails(request): postId = request.GET.get('postId',None) post = getPostById(postId) cmnts = getCommentInPost(postId) b = builder() hotCmnts = b.getnHotCmnts(postId) refs = b.getCmntReferences(hotCmnts) for cmnt in cmnts: if cmnt['id'] in hotCmnts: cmnt['hot'] = hotCmnts.index(cmnt['id']) + 1 cmnt['ref'] = refs[cmnt['id']] else: cmnt['hot'] = 0 template = get_template('commentlist.html') c = Context({'key':'val','commentList':cmnts, 'hotCmnts':hotCmnts,'post':post}) return HttpResponse(template.render(c))