Revisión: documents no route recognises; reasons and fields in Spanish
This commit is contained in:
@@ -15,6 +15,9 @@ import { conflicts } from '../api/fn/review/conflicts';
|
||||
import { correct } from '../api/fn/review/correct';
|
||||
import { decidePersons } from '../api/fn/review/decide-persons';
|
||||
import { held } from '../api/fn/review/held';
|
||||
import { Loading } from '../loading';
|
||||
import { schema } from '../api/fn/ingest/schema';
|
||||
import { unrecognised } from '../api/fn/review/unrecognised';
|
||||
import { persons } from '../api/fn/review/persons';
|
||||
import { reject } from '../api/fn/review/reject';
|
||||
import { runStatus } from '../api/fn/runs/run-status';
|
||||
@@ -46,6 +49,39 @@ const IDENTITY_FIELDS: Correction['field'][] = [
|
||||
'birth_date',
|
||||
'sex',
|
||||
];
|
||||
/** Identity fields as linkage names them (core.schema.Identity). */
|
||||
const IDENTITY_TITLES: Record<string, string> = {
|
||||
record_number: 'Expediente',
|
||||
curp: 'CURP',
|
||||
nss: 'NSS',
|
||||
full_name: 'Nombre',
|
||||
};
|
||||
|
||||
/** The platform's hold reasons (English in its logs) as the reviewer reads them. */
|
||||
const REASONS: [RegExp, (m: RegExpExecArray) => string][] = [
|
||||
[/^Field required$/, () => 'falta el dato'],
|
||||
[
|
||||
/^Input should be (.+)$/,
|
||||
(m) => `valor fuera del catálogo (se espera ${m[1].replace(/ or /g, ' o ')})`,
|
||||
],
|
||||
[/^not found in the document as quoted$/, () => 'no está en el documento tal como se citó'],
|
||||
[/^Value error, a date is not a record number$/, () => 'una fecha no es un expediente'],
|
||||
[
|
||||
/^records of this person disagree on birth date or sex$/,
|
||||
() => 'sus registros no coinciden en fecha de nacimiento o sexo',
|
||||
],
|
||||
[
|
||||
/^no name, birth date or record number was read$/,
|
||||
() => 'no se leyó nombre, fecha de nacimiento ni expediente',
|
||||
],
|
||||
[/^no identity linked to this record$/, () => 'ninguna identidad vinculada a este registro'],
|
||||
[/^nothing found$/, () => 'no se encontró nada en el documento'],
|
||||
[
|
||||
/^no LLM answering and no patterns set$/,
|
||||
() => 'sin modelo de lenguaje disponible ni patrones configurados',
|
||||
],
|
||||
];
|
||||
|
||||
/** Bookkeeping columns, not values a reviewer judges. */
|
||||
const HIDDEN = [
|
||||
'_pipeline',
|
||||
@@ -64,6 +100,7 @@ const HIDDEN = [
|
||||
@Component({
|
||||
selector: 'app-revision',
|
||||
imports: [
|
||||
Loading,
|
||||
DecimalPipe,
|
||||
KeyValuePipe,
|
||||
FormsModule,
|
||||
@@ -115,6 +152,20 @@ export class Revision {
|
||||
: Promise.resolve({ to_settle: [], torn: [] } as Record<string, Row[]>),
|
||||
});
|
||||
|
||||
/** Documents the chosen pipeline's routes don't recognise (its `otherwise` routes). */
|
||||
protected readonly unrecognised = resource({
|
||||
params: () => this.pipeline(),
|
||||
loader: ({ params }) =>
|
||||
params ? this.api.invoke(unrecognised, { pipeline: params }) : Promise.resolve([] as Row[]),
|
||||
});
|
||||
/** A row's fields but its route and preview, as `name: value`. */
|
||||
protected details(row: Row): string {
|
||||
return Object.entries(row)
|
||||
.filter(([k, v]) => !['route', 'preview'].includes(k) && v !== null && v !== '')
|
||||
.map(([k, v]) => `${k}: ${v}`)
|
||||
.join(' · ');
|
||||
}
|
||||
|
||||
protected readonly message = signal('');
|
||||
protected readonly decided = signal(new Set<string>());
|
||||
protected readonly run = signal<string>('');
|
||||
@@ -130,6 +181,48 @@ export class Revision {
|
||||
const found = row['_held'];
|
||||
return Array.isArray(found) ? found.join('; ') : String(found ?? '');
|
||||
}
|
||||
/** The platform's field titles (the catalog's), by entity: what the page calls a field. */
|
||||
protected readonly titles = resource({
|
||||
loader: async () => {
|
||||
const found = (await this.api.invoke(schema)) as Record<string, any>;
|
||||
return Object.fromEntries(
|
||||
Object.entries((found['entities'] ?? {}) as Record<string, any>).map(([e, s]) => [
|
||||
e,
|
||||
Object.fromEntries(
|
||||
Object.entries((s['properties'] ?? {}) as Record<string, any>).map(([f, p]) => [
|
||||
f,
|
||||
p['title'] as string,
|
||||
]),
|
||||
),
|
||||
]),
|
||||
) as Record<string, Record<string, string>>;
|
||||
},
|
||||
});
|
||||
protected title(field: string): string {
|
||||
return this.titles.value()?.[this.entity()]?.[field] ?? field;
|
||||
}
|
||||
/** A hold's reasons as the reviewer reads them (the platform logs them in English). */
|
||||
protected said(row: Row): string {
|
||||
const found = row['_held'];
|
||||
const all = Array.isArray(found) ? (found as string[]) : [String(found ?? '')];
|
||||
return all.map((r) => this.spanish(r)).join('; ');
|
||||
}
|
||||
/** Why linkage proposes two records as one person, in the reviewer's words. */
|
||||
protected candidateReason(reason: unknown): string {
|
||||
const text = String(reason ?? '');
|
||||
const typo = /^(\w+) one typo apart$/.exec(text);
|
||||
if (typo) return `${IDENTITY_TITLES[typo[1]] ?? typo[1]} a una letra de distancia`;
|
||||
return text === 'same birth date' ? 'misma fecha de nacimiento' : text;
|
||||
}
|
||||
private spanish(reason: string): string {
|
||||
const field = /^(\w+): (.*)$/.exec(reason);
|
||||
const [name, message] = field ? [this.title(field[1]) + ': ', field[2]] : ['', reason];
|
||||
for (const [pattern, text] of REASONS) {
|
||||
const m = pattern.exec(message);
|
||||
if (m) return name + text(m);
|
||||
}
|
||||
return reason;
|
||||
}
|
||||
protected text(value: unknown): string {
|
||||
return typeof value === 'object' && value !== null
|
||||
? JSON.stringify(value)
|
||||
|
||||
Reference in New Issue
Block a user