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 exceedmaxChars.
- 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):
prioritySectionPatternsnon-null; each entry non-null and non-blank. Empty list is allowed (no priorities = pure character-budget truncation).maxChars >= 1.onOverBudgetnon-null.
The pattern list is defensively copied on construction and exposed as unmodifiable.
- Since:
- 0.1.0
-
Constructor Summary
ConstructorsConstructorDescriptionPriorityTruncate(List<String> prioritySectionPatterns, int maxChars, OverBudgetPolicy onOverBudget) Creates an instance of aPriorityTruncaterecord class. -
Method Summary
Modifier and TypeMethodDescriptionassemble(ParsedDocument doc) Assembledocinto a single user-prompt string.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.intmaxChars()Returns the value of themaxCharsrecord component.Returns the value of theonOverBudgetrecord component.Returns the value of theprioritySectionPatternsrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
PriorityTruncate
public PriorityTruncate(List<String> prioritySectionPatterns, int maxChars, OverBudgetPolicy onOverBudget) Creates an instance of aPriorityTruncaterecord class.- Parameters:
prioritySectionPatterns- the value for theprioritySectionPatternsrecord componentmaxChars- the value for themaxCharsrecord componentonOverBudget- the value for theonOverBudgetrecord component
-
-
Method Details
-
assemble
Assembledocinto a single user-prompt string. SeeContextStrategy.assemble(ParsedDocument)and the class-level Javadoc for rules.- Specified by:
assemblein interfaceContextStrategy- 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.PriorityTruncateOverBudgetPolicy.STRICTwith priority sections exceedingmaxChars).
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
prioritySectionPatterns
Returns the value of theprioritySectionPatternsrecord component.- Returns:
- the value of the
prioritySectionPatternsrecord component
-
maxChars
-
onOverBudget
Returns the value of theonOverBudgetrecord component.- Returns:
- the value of the
onOverBudgetrecord component
-