Package com.tnsai.intelligence.knowledge
Class ContradictionDetector
java.lang.Object
com.tnsai.intelligence.knowledge.ContradictionDetector
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceStrategy for checking whether two facts conflict with each other.static final recordA detected contradiction between two temporal knowledge items. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a detector with the given conflict checker, using the system UTC clock for temporal-validity checks against existing facts.ContradictionDetector(ContradictionDetector.ConflictChecker checker, Clock clock) Creates a detector with an explicitClock— primarily for tests that pin time so they don't drift past hard-codedvalidUntilbounds. -
Method Summary
Modifier and TypeMethodDescriptiondetect(TemporalKnowledge incoming, List<TemporalKnowledge> existingFacts) Detects contradictions between an incoming fact and a list of existing facts.
-
Constructor Details
-
ContradictionDetector
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
Creates a detector with an explicitClock— primarily for tests that pin time so they don't drift past hard-codedvalidUntilbounds.- Parameters:
checker- the strategy for detecting conflicts between two factsclock- the clock used to evaluateTemporalKnowledge.isValid(java.time.Instant)
-
-
Method Details
-
detect
public List<ContradictionDetector.Contradiction> detect(TemporalKnowledge incoming, List<TemporalKnowledge> existingFacts) 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 addedexistingFacts- the existing knowledge base- Returns:
- list of detected contradictions (empty if none)
-