Record Class TemporalKnowledge

java.lang.Object
java.lang.Record
com.tnsai.intelligence.knowledge.TemporalKnowledge
Record Components:
fact - the knowledge statement
source - where this fact was extracted from
extractedAt - when this fact was extracted
validFrom - start of validity window (null = no lower bound)
validUntil - end of validity window (null = no expiry)
confidence - confidence score (0.0 to 1.0)

public record TemporalKnowledge(String fact, String source, Instant extractedAt, Instant validFrom, Instant validUntil, double confidence) extends Record
A fact with temporal validity boundaries.

Temporal knowledge associates extracted facts with a time window during which they are considered valid. This enables automatic expiration of stale knowledge and point-in-time validity checks.

Usage


 // Fact valid for 30 days from extraction
 TemporalKnowledge fact = new TemporalKnowledge(
     "Java 21 is the latest LTS release",
     "release-notes",
     Instant.now(),
     Instant.now(),
     Instant.now().plus(Duration.ofDays(30)),
     0.95
 );

 fact.isValid();   // true if within window
 fact.isExpired(); // true if past validUntil

 // Fact with no expiry
 TemporalKnowledge permanent = new TemporalKnowledge(
     "Water boils at 100C at sea level",
     "physics",
     Instant.now(),
     null,
     null,
     1.0
 );
 permanent.isValid(); // always true
 
Since:
0.3.0
Author:
TnsAI Team
  • Constructor Details

    • TemporalKnowledge

      public TemporalKnowledge(String fact, String source, Instant extractedAt, Instant validFrom, Instant validUntil, double confidence)
      Compact constructor with validation.
  • Method Details

    • isValid

      public boolean isValid()
      Checks if this knowledge is valid at the current instant.
      Returns:
      true if valid now
    • isValid

      public boolean isValid(Instant at)
      Checks if this knowledge is valid at a specific instant.
      Parameters:
      at - the instant to check
      Returns:
      true if valid at the given instant
    • isExpired

      public boolean isExpired()
      Checks if this knowledge has expired (not valid at the current instant).
      Returns:
      true if expired
    • isPermanent

      public boolean isPermanent()
      Checks if this knowledge has no expiry date.
      Returns:
      true if validUntil is null
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • fact

      public String fact()
      Returns the value of the fact record component.
      Returns:
      the value of the fact record component
    • source

      public String source()
      Returns the value of the source record component.
      Returns:
      the value of the source record component
    • extractedAt

      public Instant extractedAt()
      Returns the value of the extractedAt record component.
      Returns:
      the value of the extractedAt record component
    • validFrom

      public Instant validFrom()
      Returns the value of the validFrom record component.
      Returns:
      the value of the validFrom record component
    • validUntil

      public Instant validUntil()
      Returns the value of the validUntil record component.
      Returns:
      the value of the validUntil record component
    • confidence

      public double confidence()
      Returns the value of the confidence record component.
      Returns:
      the value of the confidence record component