import re
from unidecode import unidecode
import pandas as pd
def clean_file(input_path, output_path):
with open(input_path, 'r', encoding='utf-8') as f_in, \
open(output_path, 'w', encoding='utf-8') as f_out:
for line in f_in:
# Удаляем строки с ошибками + нормализуем текст
if not any(error in line for error in [
"Строка не распознана",
"Метка распознана",
"Пропущена",
"ADDR element ignored"
]):
line = unidecode(line) # Нормализация символов
line = re.sub(r'\s+', ' ', line.strip()) # Удаление лишних пробелов
f_out.write(line + '\n')
# Пример вызова
clean_file('new_database.txt', 'cleaned_database.txt')