-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathİsim Tespiti ve Metin Çıkartma Algoritması-2
More file actions
141 lines (140 loc) · 4.77 KB
/
İsim Tespiti ve Metin Çıkartma Algoritması-2
File metadata and controls
141 lines (140 loc) · 4.77 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import requests
import webbrowser
import cv2
import numpy as np
import os
from PIL import Image
!pip install PyPDF2
import PyPDF
import re
import io
!pip install PyMuPDF
import fitz
***************
FILETYPE=".pdf"
def düzenle(url):
return bs(requests.get(url).text, "html.parser")
def bölme_2(data):
url=data
liste_url=[]
for link in düzenle(url).find_all('a'):
file_link = link.get('href')
if FILETYPE in file_link:
liste_url.append(file_link)
liste_url_2=liste_url[int(len(liste_url)/5):2*int(len(liste_url)/5)]
return liste_url_2
***************
def arama_2(kişi,data):
liste=[]
for link in bölme_2(data):
response=requests.get(link)
try:
with io.BytesIO(response.content) as open_pdf_file:
read_pdf = PyPDF2.PdfFileReader(open_pdf_file)
num_pages = read_pdf.getNumPages()
for jj in range(read_pdf.numPages):
if (re.search(kişi,read_pdf.getPage(jj).extractText().lower())!=None)==True:
print(re.search(kişi,read_pdf.getPage(jj).extractText().lower()),jj)
file_name = link.split('/')[-1]
with open(file_name, 'wb') as file:
response = requests.get(link)
file.write(response.content)
liste.append(file_name)
except:
print("gazete yok")
return(liste)
***************
def arama_2_çoklu(kişi,kişi_2,data):
liste=[]
for link in bölme_2(data):
response=requests.get(link)
try:
with io.BytesIO(response.content) as open_pdf_file:
read_pdf = PyPDF2.PdfFileReader(open_pdf_file)
num_pages = read_pdf.getNumPages()
for jj in range(read_pdf.numPages):
if (((re.search(kişi,read_pdf.getPage(jj).extractText().lower())!=None)==True or (re.search(kişi_1,read_pdf.getPage(jj).extractText().lower())!=None)==True)) :
print(re.search(kişi,read_pdf.getPage(jj).extractText().lower()),jj)
print(re.search(kişi_1,read_pdf.getPage(jj).extractText().lower()),jj)
file_name = link.split('/')[-1]
with open(file_name, 'wb') as file:
response = requests.get(link)
file.write(response.content)
liste.append(file_name)
except:
print("gazete yok")
return(liste)
***************
bölme_2("http://nek.istanbul.edu.tr:4444/ekos/GAZETE/gazete.php?gazete=vatan")
arama_2("cahit arf","http://nek.istanbul.edu.tr:4444/ekos/GAZETE/gazete.php?gazete=vatan")
bölme_2("http://nek.istanbul.edu.tr:4444/ekos/GAZETE/gazete.php?gazete=vatan")
arama_2("mustafa inan","http://nek.istanbul.edu.tr:4444/ekos/GAZETE/gazete.php?gazete=vatan")
arama_2("ratip berker","http://nek.istanbul.edu.tr:4444/ekos/GAZETE/gazete.php?gazete=vatan")
arama_2("ratıb berker","http://nek.istanbul.edu.tr:4444/ekos/GAZETE/gazete.php?gazete=vatan")
arama_2("kerim erim","http://nek.istanbul.edu.tr:4444/ekos/GAZETE/gazete.php?gazete=vatan")
***************
def flags_decomposer(flags):
l = []
if flags & 2 ** 0:
l.append("superscript")
if flags & 2 ** 1:
l.append("italic")
if flags & 2 ** 2:
l.append("serifed")
else:
l.append("sans")
if flags & 2 ** 3:
l.append("monospaced")
else:
l.append("proportional")
if flags & 2 ** 4:
l.append("bold")
return ", ".join(l)
***************
def page_information(name,sayfa):
doc = fitz.open(name)
page = doc[sayfa]
blocks = page.get_text("dict", flags=11)["blocks"]
a=[]
for b in blocks:
for l in b["lines"]:
for s in l["spans"]:
print("")
font_properties = "Font: '%s' (%s), size %g, color #%06x" % (
s["font"], # font name
flags_decomposer(s["flags"]), # readable font flags
s["size"], # font size
s["color"], # font color
)
a.append(s)
return a
***************
def text_extraction(data,ad,soyad,sayfa):
size=[]
text=[]
font=[]
new_liste=[]
for i in page_information(data,sayfa):
aaa=list(i.values())
size.append(aaa[0])
text.append(aaa[6])
font.append(aaa[2])
try:
text_lower=[]
for j in text:
text_lower.append(j.lower())
if (text_lower.index(soyad)-text_lower.index(ad)==1):
index=text_lower.index(ad)
for ii in range(len(text)):
if ((size[index]+2 < size[ii]) or (size[index]-2 < size[ii])) and (font[index]!=font[ii]) and (int(size[index]+1)!=int(index) and ):
new_liste.append(ii)
df=pd.DataFrame(data = new_liste, columns=["sonuc"])
extracted_text=""
for kkk in text[df.values[df.values<index][-1]:df.values[df.values>index][0]]:
extracted_text=extracted_text+kkk
return extracted_text
except:
print("isim bulunmadı")
***************
text_extraction('ulus_1937_nisan_ 19.pdf',"kerim ","erim ", 2)
© 2022