Lesion size extracted from pathology reports; development record route; scenario catalog and background training jobs in governance

This commit is contained in:
rockdrigo
2026-11-21 03:28:13 -06:00
parent fae6b2232f
commit 2d71fe1103
11 changed files with 489 additions and 9 deletions
+14 -1
View File
@@ -42,6 +42,19 @@ def lineas_de_texto(texto: str, nombre: str = "texto") -> list[SegmentLine]:
return [SegmentLine(nombre, 1, Line(r, BBox(0, i * alto, 1, (i + 1) * alto))) for i, r in enumerate(renglones)]
def con_renglones_unidos(lineas: list[SegmentLine]) -> list[SegmentLine]:
"""The lines and, after them, each pair of consecutive lines of a page joined: a caption that the page wraps ("TAMAÑO
DE LA" / "LESIÓN: 25 MM") is whole in one of them. A value found in both counts as found twice, which doesn't change
which one wins."""
unidas = []
for a, b in zip(lineas, lineas[1:]):
if a.page_number != b.page_number or a.document != b.document:
continue
caja = BBox(min(a.line.bbox.x0, b.line.bbox.x0), a.line.bbox.y0, max(a.line.bbox.x1, b.line.bbox.x1), b.line.bbox.y1)
unidas.append(SegmentLine(a.document, a.page_number, Line(f"{a.line.text} {b.line.text}", caja), a.ocr or b.ocr))
return [*lineas, *unidas]
def lineas_de_pdf(contenido: bytes) -> list[SegmentLine]:
"""The text layer of a PDF, without OCR: a load doesn't run OCR, and a scan without text gives no lines."""
try:
@@ -74,7 +87,7 @@ class DesdeTexto:
@lru_cache(maxsize=256)
def extraer(contenido: str | bytes) -> dict[str, tuple]:
lineas = lineas_de_pdf(contenido) if isinstance(contenido, bytes) else lineas_de_texto(contenido)
lineas = con_renglones_unidos(lineas_de_pdf(contenido) if isinstance(contenido, bytes) else lineas_de_texto(contenido))
leidos = extractor.extract(lineas)
return {r: _valor_y_fuente(leidos.get(r), leidos.get(r + SUFIJO_DE_TEXTO), tipos[r]) for r in tipos}