opennlp.tools.langdetect

## Class LanguageDetectorME

- java.lang.Object
- - opennlp.tools.langdetect.LanguageDetectorME

- All Implemented Interfaces:
    Serializable, LanguageDetector

      public class LanguageDetectorME
      extends Object
      implements LanguageDetector

  Implements learnable Language Detector

  This will process the entire string when called with `predictLanguage(CharSequence)` or `predictLanguages(CharSequence)`.

  If you want this to stop early, use `probingPredictLanguages(CharSequence)` or `probingPredictLanguages(CharSequence, LanguageDetectorConfig)`. When run in probing mode, this starts at the beginning of the charsequence and runs language detection on chunks of text. If the end of the string is reached or there are `LanguageDetectorConfig.getMinConsecImprovements()` consecutive predictions for the best language and the confidence increases over those last predictions and if the difference in confidence between the highest confidence language and the second highest confidence language is greater than `LanguageDetectorConfig.getMinDiff()`, the language detector will stop and report the results.

  The authors wish to thank Ken Krugler and Yalder} for the inspiration for many of the design components of this detector.

  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `LanguageDetectorME(LanguageDetectorModel model)` Initializes the current instance with a language detector model.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `String[]` | `getSupportedLanguages()`
    `Language` | `predictLanguage(CharSequence content)` This will process the full content length.
    `Language[]` | `predictLanguages(CharSequence content)` This will process the full content length.
    `ProbingLanguageDetectionResult` | `probingPredictLanguages(CharSequence content)` This will stop processing early if the stopping criteria specified in `LanguageDetectorConfig.DEFAULT_LANGUAGE_DETECTOR_CONFIG` are met.
    `ProbingLanguageDetectionResult` | `probingPredictLanguages(CharSequence content, LanguageDetectorConfig config)` This will stop processing early if the stopping criteria specified in `LanguageDetectorConfig.DEFAULT_LANGUAGE_DETECTOR_CONFIG` are met.
    `static LanguageDetectorModel` | `train(ObjectStream<LanguageSample> samples, TrainingParameters mlParams, LanguageDetectorFactory factory)`

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

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

- - ### Constructor Detail

    - #### LanguageDetectorME

          public LanguageDetectorME(LanguageDetectorModel model)

      Initializes the current instance with a language detector model. Default feature generation is used.
      Parameters:
        `model` - the language detector model

  - ### Method Detail

    - #### predictLanguages

          public Language[] predictLanguages(CharSequence content)

      This will process the full content length.
      Specified by:
        `predictLanguages` in interface `LanguageDetector`
      Parameters:
        `content` -
      Returns:
        the predicted languages

    - #### predictLanguage

          public Language predictLanguage(CharSequence content)

      This will process the full content length.
      Specified by:
        `predictLanguage` in interface `LanguageDetector`
      Parameters:
        `content` -
      Returns:
        the language with the highest confidence

    - #### getSupportedLanguages

          public String[] getSupportedLanguages()

      Specified by:
        `getSupportedLanguages` in interface `LanguageDetector`

    - #### probingPredictLanguages

          public ProbingLanguageDetectionResult probingPredictLanguages(CharSequence content)

      This will stop processing early if the stopping criteria specified in `LanguageDetectorConfig.DEFAULT_LANGUAGE_DETECTOR_CONFIG` are met.
      Parameters:
        `content` - content to be processed
      Returns:
        result

    - #### probingPredictLanguages

          public ProbingLanguageDetectionResult probingPredictLanguages(CharSequence content,
                                                                        LanguageDetectorConfig config)

      This will stop processing early if the stopping criteria specified in `LanguageDetectorConfig.DEFAULT_LANGUAGE_DETECTOR_CONFIG` are met.
      Parameters:
        `content` - content to process
        `config` - config to customize detection
      Returns:

    - #### train

          public static LanguageDetectorModel train(ObjectStream<LanguageSample> samples,
                                                    TrainingParameters mlParams,
                                                    LanguageDetectorFactory factory)
                                             throws IOException

      Throws:
        `IOException`

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