Files
doc_ebook_checker/procesa_documentos.py
T
2026-07-31 21:17:36 +02:00

50 lines
1.4 KiB
Python

from docx import Document
import language_tool_python
import os, sys
import pdb
#un comentario de mierda sobre el nombre del fichero
fishero = "c:\\DATOS\\DOCS\\!NOM\\SPANISH\\1_MITROKHIN\\El archivo Mitrokhin - El KGB en Europa y Occidente - Christopher Andrew, Vasili Mitrokhin Z-Library-mono.docx"
checker_tool = language_tool_python.LanguageTool('es')
f = open(fishero, 'rb')
document = Document(f)
offset = 0
nroPara = 1
nroParas = len(document.paragraphs)
for para in document.paragraphs:
start = offset
end = start + len(para.text)
if para.style.name == "Heading 1":
print(f"{para.text.replace(chr(9), " "):80s} => Rango = {start} to {end}")
else:
text = para.text
matches = checker_tool.check(text)
nroMatch = 1
for match in matches:
print(f"Rule[{nroMatch}]: {match.rule_id}")
print(f"Message: {match.message}")
print(f"Error: '{text[match.offset:match.offset+match.error_length]}'")
print("Suggestions:", match.replacements)
print("Context: ", match.context)
print()
nroMatch += 1
#if nroMatch > 3:
# break
print(f"=[{nroPara:5d}/{nroParas:5d}]========================================")
offset = end + 1
nroPara += 1
#pdb.set_trace()
f.close()