Source forms as a partial, non-injective function into the catalog's codes, checked on the catalog
How: `reference.source_mapping` keys a mapping by source system, result, normalized form and validity; `check_function` rejects a form that gives two codes while both mappings are in force, and `resolve` gives the code in force on a date, or none when nothing or two disagreeing mappings match. The catalog's own check of spellings (`_claves_de_extraccion`) now runs `check_function` on each result's codes, labels and aliases. Implications: the same rule serves the TOML today and any store of mappings with systems and dates; every catalog passes it.
This commit is contained in:
@@ -15,10 +15,10 @@ from pathlib import Path
|
||||
from typing import NamedTuple
|
||||
|
||||
import core
|
||||
from extraction.nlp.text import fold
|
||||
from core.indicadores.catalogos import TIPOS_DE_VALOR
|
||||
from sqlmodel import SQLModel
|
||||
|
||||
from webapi.orchestration.reference.source_mapping import check_function, from_result
|
||||
from webapi.orchestration.tables import TablasKit
|
||||
|
||||
# Los catálogos viven en Core, junto a los modelos de sus tablas.
|
||||
@@ -165,7 +165,8 @@ def resultados_extraibles(proyecto: str) -> dict[str, ResultadoExtraible]:
|
||||
|
||||
|
||||
def _claves_de_extraccion(resultado: dict, resultado_id: str) -> None:
|
||||
"""The extraction keys of a result: captions as a non-empty list of texts, and no spelling on two values."""
|
||||
"""The extraction keys of a result: captions as a non-empty list of texts, and its spellings a function into
|
||||
its values (`source_mapping.check_function`)."""
|
||||
etiquetas = resultado.get("etiquetas_fuente")
|
||||
if etiquetas is not None and (not isinstance(etiquetas, list) or not etiquetas
|
||||
or not all(isinstance(e, str) and e.strip() for e in etiquetas)):
|
||||
@@ -176,15 +177,10 @@ def _claves_de_extraccion(resultado: dict, resultado_id: str) -> None:
|
||||
raise CatalogoInvalido(f"{resultado_id}: un resultado de tipo {resultado.get('tipo_valor')} no se extrae de texto.")
|
||||
if resultado.get("buscar_en_texto") and resultado.get("tipo_valor") != "codigo":
|
||||
raise CatalogoInvalido(f"{resultado_id}: solo un resultado de tipo codigo se busca como mención en el texto.")
|
||||
de: dict[str, str] = {}
|
||||
for valor in resultado.get("valores", ()):
|
||||
for forma in (valor.get("etiqueta", ""), *valor.get("alias", ())):
|
||||
clave = " ".join(fold(forma).split())
|
||||
if de.get(clave, valor["valor"]) != valor["valor"]:
|
||||
raise CatalogoInvalido(
|
||||
f"{resultado_id}: {forma!r} se escribe igual para {de[clave]!r} y {valor['valor']!r}."
|
||||
)
|
||||
de[clave] = valor["valor"]
|
||||
try:
|
||||
check_function(from_result(resultado_id, resultado))
|
||||
except ValueError as e:
|
||||
raise CatalogoInvalido(str(e)) from None
|
||||
|
||||
|
||||
def _leer(ruta: Path) -> dict:
|
||||
|
||||
Reference in New Issue
Block a user