Class MibChunkFormatter

java.lang.Object
org.snmp4j.mcp.tool.mib.semantic.MibChunkFormatter

public class MibChunkFormatter extends Object
Converts a SmiObject into one or more plain-text chunks suitable for embedding.

Uses the object's DESCRIPTION text. Short descriptions (≤ DEFAULT_MAX_WORDS words) are returned as a single chunk. Longer descriptions are split into paragraph-aligned chunks, each below the word limit, with a sliding overlap between consecutive chunks so that relevant context is not lost at chunk boundaries.

Chunking strategy:

  1. Split the text on blank-line paragraph separators. If only one paragraph results, fall back to sentence-level splits.
  2. Greedily pack paragraphs into a chunk while the running word count stays below DEFAULT_MAX_WORDS.
  3. Start the next chunk with the trailing ~30% of words of the previous chunk (within the [DEFAULT_MIN_OVERLAP_RATIO, DEFAULT_MAX_OVERLAP_RATIO] range) before appending further paragraphs.
Since:
0.1.0
  • Field Details

    • DEFAULT_MAX_WORDS

      public static final int DEFAULT_MAX_WORDS
      Maximum words per chunk (exclusive upper bound).
      See Also:
    • DEFAULT_MIN_OVERLAP_RATIO

      public static final double DEFAULT_MIN_OVERLAP_RATIO
      Minimum overlap ratio between consecutive chunks.
      See Also:
    • DEFAULT_MAX_OVERLAP_RATIO

      public static final double DEFAULT_MAX_OVERLAP_RATIO
      Maximum overlap ratio between consecutive chunks.
      See Also:
  • Constructor Details

    • MibChunkFormatter

      public MibChunkFormatter()
      Creates a formatter with default chunk size and overlap.
    • MibChunkFormatter

      public MibChunkFormatter(int maxWords, double minOverlapRatio, double maxOverlapRatio)
      Creates a formatter with custom chunk size and overlap window.
      Parameters:
      maxWords - hard upper bound on words per chunk (must be > 1)
      minOverlapRatio - minimum overlap ratio in (0, 0.5)
      maxOverlapRatio - maximum overlap ratio in (0, 0.5); must be ≥ minOverlapRatio
  • Method Details

    • format

      public List<String> format(com.snmp4j.smi.SmiObject obj)
      Splits the object's DESCRIPTION text into embeddable chunks.
      Parameters:
      obj - the MIB object to format (non-null)
      Returns:
      one chunk for short descriptions, multiple paragraph-aligned chunks for longer ones, or an empty list when the description is missing or blank