PageRank: Django view and the algorithm code
To rank the importance of the online reviews, we have implemented the PageRank algorithm (see Chapter 4, Web Mining Techniques, in the Ranking: PageRank algorithm section) into the application. The pgrank.py
file in the pgrank
folder within the webmining_server
folder implements the algorithm that follows:
from pages.models import Page,SearchTerm num_iterations = 100000 eps=0.0001 D = 0.85 def pgrank(searchid): s = SearchTerm.objects.get(id=int(searchid)) links = s.links.all() from_idxs = [i.from_id for i in links ] # Find the idxs that receive page rank links_received = [] to_idxs = [] for l in links: from_id = l.from_id to_id = l.to_id if from_id not in from_idxs: continue if to_id not in from_idxs: continue links_received.append([from_id,to_id]) if to_id not in to_idxs: to_idxs.append(to_id) pages = s.pages.all() prev_ranks = dict() for node...