Class ContradictionDetector

java.lang.Object
com.tnsai.intelligence.knowledge.ContradictionDetector

public class ContradictionDetector extends Object
Detects contradictions between incoming and existing temporal knowledge.

Uses a pluggable ContradictionDetector.ConflictChecker to determine whether two facts contradict each other. Only currently valid facts are checked.

Usage


 // Simple keyword-based checker
 ContradictionDetector detector = new ContradictionDetector(
     (a, b) -> {
         if (a.contains("Java 21") && b.contains("Java 17") &&
             a.contains("latest LTS") && b.contains("latest LTS")) {
             return Optional.of("Conflicting LTS version claims");
         }
         return Optional.empty();
     }
 );

 List<Contradiction> issues = detector.detect(incomingFact, existingFacts);
 
Since:
0.3.0
Author:
TnsAI Team
  • Constructor Details

    • ContradictionDetector

      public ContradictionDetector(ContradictionDetector.ConflictChecker checker)
      Creates a detector with the given conflict checker, using the system UTC clock for temporal-validity checks against existing facts.
      Parameters:
      checker - the strategy for detecting conflicts between two facts
    • ContradictionDetector

      public ContradictionDetector(ContradictionDetector.ConflictChecker checker, Clock clock)
      Creates a detector with an explicit Clock — primarily for tests that pin time so they don't drift past hard-coded validUntil bounds.
      Parameters:
      checker - the strategy for detecting conflicts between two facts
      clock - the clock used to evaluate TemporalKnowledge.isValid(java.time.Instant)
  • Method Details

    • detect

      Detects contradictions between an incoming fact and a list of existing facts.

      Only existing facts that are currently valid are checked.

      Parameters:
      incoming - the new fact being added
      existingFacts - the existing knowledge base
      Returns:
      list of detected contradictions (empty if none)