8
8
fexi_pattern = re .compile (r'ΦΕΞΗ|ΒΙΒΛΙΟΘΗΚΗ|ΒΙΒΛΙΟΠΩΛΕΙΟΝ|^ΕΚΔΟΤΗΣ|ΕΝ ΑΘΗΝΑΙΣ|ΤΥΠΟΓΡΑΦΕΙΟΥ|ΒΙΒΛΙΟΓΡΑΦΙΑ|ΠΙΝΑΞ ΤΩΝ ΕΙΚΟΝΩΝ' )
9
9
exception_to_fexi_intro_pattern = re .compile (r'ΕΚΔΟΤΙΚΟΣ ΟΙΚΟΣ ΓΕΩΡΓΙΟΥ Δ. ΦΕΞΗ' )
10
10
unique_line_remove_pattern = re .compile (r'ΒΑΣΙΛΙΚΟΝ ΤΥΠΟΓΡΑΦΕΙΟΝ' )
11
- fexi_end_intro = re .compile (r'ΕΝ ΑΘΗΝΑΙΣ|(1[8-9][0-9][0-9])$|ΕΙΣΑΓΩΓΗ|ΠΡΟΛΟΓΟΣ|ΠΡΟΣΩΠΑ|ΤΑ ΦΟΡΕΜΑΤΑ|ΕΚΔΟΤΙΚΟΣ ΟΙΚΟΣ ΓΕΩΡΓΙΟΥ ΦΕΞΗ|ΕΙΣΗΓΗΣΙΣ|ΒΙΒΛΙΟΝ|ΤΟΜΟΣ|ΕΚΔΟΤΗΣ|ΕΚΔΟΣΕΙΣ ΦΕΞΗ|ΚΕΦΑΛΑΙΟΝ|Κεφάλαιον|Α\'\.|ΚΕΦΑΛΑΙΟ I.|(\(1[8-9][0-9][0-9]\))$|Η ΥΠΟΘΕΣΙΣ ΤΟΥ ΔΡΑΜΑΤΟΣ|ΠΡΟΛΕΓΟΜΕΝΑ|ΠΡΑΞΙΣ|ΒΙΒΛΙΟ ΠΡΩΤΟ.' )
11
+ fexi_end_intro = re .compile (r'ΕΝ ΑΘΗΝΑΙΣ|(1[8-9][0-9][0-9].? )$|ΕΙΣΑΓΩΓΗ|ΠΡΟΛΟΓΟΣ|ΠΡΟΣΩΠΑ|ΤΑ ΦΟΡΕΜΑΤΑ|ΕΚΔΟΤΙΚΟΣ ΟΙΚΟΣ ΓΕΩΡΓΙΟΥ ΦΕΞΗ|ΕΙΣΗΓΗΣΙΣ|ΒΙΒΛΙΟΝ|ΤΟΜΟΣ|ΕΚΔΟΤΗΣ|ΕΚΔΟΣΕΙΣ ΦΕΞΗ|ΚΕΦΑΛΑΙΟΝ|Κεφάλαιον|Α\'\.|ΚΕΦΑΛΑΙΟ I.|(\(1[8-9][0-9][0-9]\))$|Η ΥΠΟΘΕΣΙΣ ΤΟΥ ΔΡΑΜΑΤΟΣ|ΠΡΟΛΕΓΟΜΕΝΑ|ΠΡΑΞΙΣ|ΒΙΒΛΙΟ ΠΡΩΤΟ.|Τι είναι βουδδισμός;|PREFACE|ΑΡΙΣΤΟΤΕΛΗΣ ΒΑΛΑΩΡΙΤΗΣ|ΓΙΑ ΤΟΥΤΟ ΤΟ ΒΙΒΛΙΟ|ΠΑΡΑΜΥΘΙ ΧΩΡΙΣ ΟΝΟΜΑ ' )
12
12
content_pattern = re .compile (r'ΠΕΡΙΕΧΟΜΕΝΑ|ΕΜΠΕΡΙΕΧΟΜΕΝΑ|ΠΙΝΑΚΑΣ ΠΕΡΙΕΧΟΜΕΝΩΝ|Π Ι Ν Α Κ Α Σ Π Ε Ρ Ι Ε Χ Ο Μ Ε Ν Ω Ν|Π Ρ Ο Σ Ω Π Α|ΠΡΟΣΩΠΑ|Π Ι Ν Α Κ Α Σ Π Ε Ρ Ι Ε Χ Ο Μ Ε Ν Ω Ν|ΤΑ ΤΗΣ ΤΡΑΓΩΔΙΑΣ ΠΡΟΣΩΠΑ|ΠΕΡΙΕΧΟΜΕΝA|ΠΑΡΑΡΤΗΜΑ|ΠΙΝΑΚΑΣ|( )*ΟΙ ΠΑΡΑΔΑΡΜΕΝΟΙ|Τ Α Π Ρ Ο Σ Ω Π Α Τ Ο Υ Δ Ρ Α Μ Α Τ Ο Σ|ΠΡΟΣΩΠΑ ΤΟΥ ΔΡΑΜΑΤΟΣ|Τα πρόσωπα της τραγωδίας|ΤΑ ΠΡΟΣΩΠΑ ΤΟΥ ΔΡΑΜΑΤΟΣ' )
13
13
re_clean_end_pattern = re .compile (r'ΕΚΛΕΚΤΑ ΕΡΓΑ|\*\*\*|\* \* \*|ΠΙΝΑΚΑΣ|ΤΕΥΧΗ ΕΚΔΟΘΕΝΤΑ|Σ Η Μ Ε I Ω Σ Ε Ι Σ|ΠΡΟΠΟΜΠΟΙ|Δ Ι Ο Ρ Θ Ω Σ Ε Ι Σ|_Πίναξ|ΤΕΛΟΣ ΤΟΥ ΠΡΩΤΟΥ ΤΟΜΟΥ|ΠΙΝΑΞ|ΝΤΟΠΙΕΣ ΖΩΓΡΑΦΙΕΣ|ΤΕΛΟΣ|.?1[\)\}\]]|ΠΕΡΙΕΧΟΜΕΝΑ' )
14
+ out_pattern = re .compile (r'\[Out' )
14
15
15
16
no_greek_pattern = re .compile (r'([Α-Ω]+)|([α-ω]+)' , re .UNICODE )
16
17
#end_note_pattern = re.compile(r'(1)|1)|1}|1}|[1]|1]')
@@ -123,12 +124,18 @@ def remove_latin_text(text) :
123
124
newtext = newtext + line + '\n '
124
125
return newtext
125
126
126
- def re_remove (text ) :
127
+ def re_remove (text , num_of_file ) :
127
128
newtext = ''
128
129
lines = text .splitlines ()
129
130
non_capital_pattern = re .compile (r'([α-ω][α-ω])+' )
130
131
re_clean_end_found_flag = False
132
+ flag_prob_fail = False
131
133
for i ,line in enumerate (lines ) :
134
+ if re .match (out_pattern ,line ) :
135
+ #if i > len(lines)/4 and i < len(lines)/3 and flag_prob_fail == False :
136
+ #print('Probable Failure at ',num_of_file)
137
+ #flag_prob_fail = True
138
+ continue
132
139
if i > 105 and i < len (lines ) - 300 :
133
140
newtext = newtext + line + '\n '
134
141
continue
@@ -139,15 +146,40 @@ def re_remove(text) :
139
146
newtext = newtext + line + '\n '
140
147
continue
141
148
if re_clean_end_found_flag == True :
142
- newtext = newtext + '[Out:End of text, Second clean]' + line + '\n '
149
+ # newtext = newtext+'[Out:End of text, Second clean]'+line+'\n'
143
150
continue
144
151
if i < 105 :
145
152
if not re .search (non_capital_pattern ,line ) :
146
- newtext = newtext + '[Out:Pures Capitals/No greek characters in first 105 lines]' + line + '\n '
153
+ # newtext = newtext+'[Out:Pures Capitals/No greek characters in first 105 lines]'+line+'\n'
147
154
continue
148
155
newtext = newtext + line + '\n '
149
156
return newtext
150
157
158
+ def remove_extras (text ) :
159
+ intro_white_space_flag = True
160
+ beginning_pattern = re .compile (r'[Α-Ω]' )
161
+ lines = text .splitlines ()
162
+ newtext = ''
163
+ for line in lines :
164
+ if re .match (beginning_pattern ,line ) :
165
+ intro_white_space_flag = False
166
+ if intro_white_space_flag :
167
+ newtext = newtext + '[Out:Greek Text not begun]' + line + '\n '
168
+ continue
169
+ newtext = newtext + line + '\n '
170
+ return newtext
171
+
172
+ def remove_publisher_note (text ) :
173
+ ekdotis_pattern = re .compile (r'.+Ο ΕΚΔΟΤΗΣ' ,re .DOTALL )
174
+ if re .match (ekdotis_pattern , text ) :
175
+ re .sub (ekdotis_pattern , '[Out' + re .match (ekdotis_pattern , text ).group (0 )+ ']' ,text )
176
+ return text
177
+
178
+ def precision_cleaning (text ) :
179
+ text = remove_extras (text )
180
+ text = remove_publisher_note (text )
181
+ return text
182
+
151
183
def clean (pathout ,pathin ) :
152
184
os .makedirs (pathout , exist_ok = True )
153
185
for i ,file in enumerate (os .listdir (pathin )) :
@@ -160,7 +192,8 @@ def clean(pathout,pathin) :
160
192
print (f"Error reading { file } : { e } " )
161
193
continue
162
194
text = remove_latin_text (text )
163
- text = re_remove (text )
195
+ text = re_remove (text ,file )
196
+ text = precision_cleaning (text )
164
197
output_file_path = os .path .join (pathout , file )
165
198
try :
166
199
with open (output_file_path , 'w' , encoding = 'utf-8' ) as output_file :
0 commit comments