-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeywords.py
More file actions
40 lines (30 loc) · 997 Bytes
/
keywords.py
File metadata and controls
40 lines (30 loc) · 997 Bytes
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
import heapq
from stem import stemming
import copy
class Keyword:
words_dict = {}
fetched = False
@classmethod
def add_keyword(cls, word, link):
"""adds new element to dict of keyword and links"""
if word in cls.words_dict:
heapq.heappush(cls.words_dict[word], link)
else:
cls.words_dict.setdefault(word, [])
heapq.heappush(cls.words_dict[word], link)
@classmethod
def update(cls, url):
"""updates pagerank and remodifies words_dict order"""
for word in cls.words_dict:
for l in cls.words_dict[word]:
if l.link == url:
l.update_pagerank()
@classmethod
def give_dict(cls):
final_dict = {}
for key in cls.words_dict:
l = []
while cls.words_dict[key] != []:
l.append(heapq.heappop(cls.words_dict[key]).link)
final_dict[key] = l
return final_dict