opennlp.tools.doccat

## Class NGramFeatureGenerator

- java.lang.Object
- - opennlp.tools.doccat.NGramFeatureGenerator

- All Implemented Interfaces:
    FeatureGenerator

      public class NGramFeatureGenerator
      extends Object
      implements FeatureGenerator

  Generates ngram features for a document. n-gram `FeatureGenerator`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `NGramFeatureGenerator()` Default constructor for Bi grams
    `NGramFeatureGenerator(int minGram, int maxGram)` Constructor for ngrams.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Collection<String>` | `extractFeatures(String[] text, Map<String,Object> extraInfo)` Extract ngram features from given text fragments

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### NGramFeatureGenerator

          public NGramFeatureGenerator(int minGram,
                                       int maxGram)
                                throws InvalidFormatException

      Constructor for ngrams.
      Parameters:
        `minGram` - minGram value - which means minimum words in ngram features
        `maxGram` - maxGram value - which means maximum words in ngram features
      Throws:
        `InvalidFormatException`

    - #### NGramFeatureGenerator

          public NGramFeatureGenerator()
                                throws InvalidFormatException

      Default constructor for Bi grams
      Throws:
        `InvalidFormatException`

  - ### Method Detail

    - #### extractFeatures

          public Collection<String> extractFeatures(String[] text,
                                                    Map<String,Object> extraInfo)

      Extract ngram features from given text fragments
      Specified by:
        `extractFeatures` in interface `FeatureGenerator`
      Parameters:
        `text` - the text fragments to extract features from
        `extraInfo` - optional extra information
      Returns:
        a collection of n gram features

Copyright © 2026 The Apache Software Foundation. All rights reserved.