-
Notifications
You must be signed in to change notification settings - Fork 1
/
indexer.py
55 lines (42 loc) · 1.23 KB
/
indexer.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
import PyPDF2
import requests
import nltk
from nltk.corpus import stopwords
from nltk.stem import SnowballStemmer
stemer = SnowballStemmer("english")
data = {}
pdf_file = open('Jul_2013_SOLE SANJAY SHRIVANT.pdf', 'rb')
pdf = PyPDF2.PdfFileReader(pdf_file)
page_count = pdf.getNumPages()
print(page_count)
for page_no in range(0, page_count):
pageObj = pdf.getPage(page_no)
data[page_no] = pageObj.extractText()
# print(pageObj.extractText())
# print(data)
stop = set(stopwords.words("english"))
imp = {}
token=[]
for num, value in data.items():
word = nltk.word_tokenize(value)
tag_word = nltk.tag.pos_tag(word)
token.append([t.lower() for t, tag in tag_word if t not in stop if tag == 'NNP'])
#print(token[num])
wordfreq = nltk.FreqDist(token[num])
#print(wordfreq.most_common(10))
imp[num+1] = [t for t,key in wordfreq.most_common(10)]
req={}
for key, value in imp.items():
for word in value:
if word in req:
continue
a=[key]
req[word]=a
for i in range(key,page_count):
if word in token[i]:
req[word].append(i+1)
for word, num in req.items():
print(word+" : ", end=' ')
for i in num:
print(i,end=' ')
print()