-
Notifications
You must be signed in to change notification settings - Fork 0
/
nltk_pdf.py
83 lines (49 loc) · 1.67 KB
/
nltk_pdf.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import socket
import fitz
import nltk
import string
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
from collections import Counter
from _collections import OrderedDict
from nltk.corpus import stopwords
nltk.download('punkt')
HOST = "localhost"
PORT = 3035
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print('Socket created')
s.bind((HOST, PORT))
s.listen()
print("Socket Listening")
conn, addr = s.accept()
conn.send(bytes("Message"+"\r\n",'UTF-8'))
print("Message sent")
data = conn.recv(1024)
urlcadena=data.decode(encoding='UTF-8')
def sube(nombrearchivo):
doc=fitz.open(nombrearchivo)
salida=open(nombrearchivo+".txt","wb")
for pagina in doc:
texto=pagina.getText().encode("utf8")
salida.write(texto.lower())
salida.write(b"\n-----\n")
salida.close()
with open(nombrearchivo+'.txt','r',encoding='UTF8') as archivo:
texto = archivo.read();
stop_words = set(stopwords.words(fileids=('english', 'spanish')))
word_tokens=word_tokenize(texto)
word_tokens=list(filter(lambda token: token not in string.punctuation,word_tokens))
#areglo=[]
#word_tokens.append("--")
filtro=[]
for palabra in word_tokens:
if palabra not in stop_words:
filtro.append(palabra)
c=Counter(filtro)
y=OrderedDict(c.most_common())
with open(nombrearchivo+'KEYWORDS.txt','w',encoding='UTF8') as far:
for k,v in y.items():
far.write(f"{k} {v}\n")
#sube("C:\\TESIS REMIGIO FINAL\\wildfly-20.0.0.Final\\wildfly-20.0.0.Final\\standalone\\deployments\\SistemaWebSociedadLector.war/resources/docs/3 4G tecnologias.pdf");
sube(urlcadena);
conn.close()