File size: 1,448 Bytes
fc93158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
 * fact-checker.ts
 * Validador de consistencia para la Capa NLE.
 * Utilidad: Detecta contradicciones lógicas entre el estado observado y las inferencias.
 */

import { LogicPredicate } from "./types.js";

export class NLEFactChecker {
  /**
   * Valida si un nuevo predicado contradice la base de conocimientos actual.
   * Criterio falsable: Si existe P y NO P con truthValue alto, hay una ruptura de coherencia.
   */
  public verify(
    newPredicate: LogicPredicate,
    existing: LogicPredicate[],
  ): { valid: boolean; conflict?: string } {
    // Ejemplo de regla de contradicción: system_idle vs system_busy
    if (newPredicate.id === "system_idle" && newPredicate.truthValue > 0.8) {
      const busy = existing.find((p) => p.id === "system_busy" && p.truthValue > 0.8);
      if (busy) {
        return {
          valid: false,
          conflict: "Contradiction: system cannot be idle and busy simultaneously.",
        };
      }
    }

    // Regla de viabilidad: si hay correction_needed pero no hay recursos (costStress muy alto)
    if (newPredicate.id === "correction_needed" && newPredicate.truthValue > 0.5) {
      const costStress = existing.find((p) => p.id === "high_cost_stress" && p.truthValue > 0.9);
      if (costStress) {
        return {
          valid: false,
          conflict: "Infeasible: correction needed but metabolic cost is too high.",
        };
      }
    }

    return { valid: true };
  }
}