Table of Contents

Class SentenceCompressor

Namespace
AiDotNet.PromptEngineering.Compression
Assembly
AiDotNet.dll

Compressor that shortens sentences while preserving their core meaning.

public class SentenceCompressor : PromptCompressorBase, IPromptCompressor
Inheritance
SentenceCompressor
Implements
Inherited Members

Remarks

This compressor analyzes sentence structure and removes non-essential clauses, qualifiers, and modifiers while maintaining grammatical correctness and the primary message.

For Beginners: Makes sentences shorter by keeping only the important parts.

Example:

var compressor = new SentenceCompressor();

string verbose = "In the following section, I will provide you with a detailed explanation of how the algorithm works, step by step.";
string compressed = compressor.Compress(verbose);
// Result: "Here's how the algorithm works, step by step."

What gets simplified:

  • Introductory phrases removed
  • Complex clauses simplified
  • Passive voice converted to active (when possible)

Constructors

SentenceCompressor(Func<string, int>?)

Initializes a new instance of the SentenceCompressor class.

public SentenceCompressor(Func<string, int>? tokenCounter = null)

Parameters

tokenCounter Func<string, int>

Optional custom token counter function.

Methods

CompressCore(string, CompressionOptions)

Compresses the prompt by simplifying sentences.

protected override string CompressCore(string prompt, CompressionOptions options)

Parameters

prompt string
options CompressionOptions

Returns

string