Record Class PriorityTruncate

java.lang.Object
java.lang.Record
ai.doctruth.PriorityTruncate
Record Components:
prioritySectionPatterns - substrings (case-insensitive) that mark a section as priority — included even when the budget is tight.
maxChars - soft character budget for the assembled context.
onOverBudget - policy for the case where priority sections alone exceed maxChars.
All Implemented Interfaces:
ContextStrategy

public record PriorityTruncate(List<String> prioritySectionPatterns, int maxChars, OverBudgetPolicy onOverBudget) extends Record implements ContextStrategy
Smart-context strategy for keeping priority sections while trimming everything else to fit. Patterns are matched against the rendered text of each section using a case-insensitive substring check — kept deliberately dumb at this layer; users own the vocabulary (e.g. "Qualifications", "评分标准").

Invariants (compact constructor):

  • prioritySectionPatterns non-null; each entry non-null and non-blank. Empty list is allowed (no priorities = pure character-budget truncation).
  • maxChars >= 1.
  • onOverBudget non-null.

The pattern list is defensively copied on construction and exposed as unmodifiable.

Since:
0.1.0
  • Constructor Details

    • PriorityTruncate

      public PriorityTruncate(List<String> prioritySectionPatterns, int maxChars, OverBudgetPolicy onOverBudget)
      Creates an instance of a PriorityTruncate record class.
      Parameters:
      prioritySectionPatterns - the value for the prioritySectionPatterns record component
      maxChars - the value for the maxChars record component
      onOverBudget - the value for the onOverBudget record component
  • Method Details

    • assemble

      public String assemble(ParsedDocument doc) throws ExtractionException
      Assemble doc into a single user-prompt string. See ContextStrategy.assemble(ParsedDocument) and the class-level Javadoc for rules.
      Specified by:
      assemble in interface ContextStrategy
      Parameters:
      doc - the parsed document; must not be null.
      Returns:
      a single string suitable for use as the user prompt.
      Throws:
      ExtractionException - if the strategy cannot satisfy its budget contract (e.g. PriorityTruncate OverBudgetPolicy.STRICT with priority sections exceeding maxChars).
    • 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 the compare method from their corresponding wrapper classes.
      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.
    • prioritySectionPatterns

      public List<String> prioritySectionPatterns()
      Returns the value of the prioritySectionPatterns record component.
      Returns:
      the value of the prioritySectionPatterns record component
    • maxChars

      public int maxChars()
      Returns the value of the maxChars record component.
      Returns:
      the value of the maxChars record component
    • onOverBudget

      public OverBudgetPolicy onOverBudget()
      Returns the value of the onOverBudget record component.
      Returns:
      the value of the onOverBudget record component