MCPcopy Index your code
hub / github.com/apache/opennlp

github.com/apache/opennlp @opennlp-3.0.0-M4

Chat with this repo
repository ↗ · DeepWiki ↗ · release opennlp-3.0.0-M4 ↗ · + Follow
8,560 symbols 32,664 edges 1,316 files 2,908 documented · 34% updated 2d agoopennlp-3.0.0-M4 · 2026-06-30★ 1,604
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Welcome to Apache OpenNLP!

GitHub license Maven Central Documentation Status Build Status Contributors GitHub pull requests OpenSSF Scorecard

The Apache OpenNLP library is a machine learning based toolkit for the processing of natural language text.

This toolkit is written completely in Java and provides support for common NLP tasks, such as tokenization, sentence segmentation, part-of-speech tagging, named entity extraction, chunking, parsing, coreference resolution, language detection, stopword filtering (with bundled lists for 11 languages) and more!

These tasks are usually required to build more advanced text processing services.

The goal of the OpenNLP project is to be a mature toolkit for the above mentioned tasks.

An additional goal is to provide a large number of pre-built models for a variety of languages, as well as the annotated text resources that those models are derived from.

Presently, OpenNLP includes common classifiers such as Maximum Entropy, Perceptron, Naive Bayes and Support Vector Machines (SVM).

OpenNLP can be used both programmatically through its Java API or from a terminal through its CLI. OpenNLP API can be easily plugged into distributed streaming data pipelines like Apache Flink, Apache NiFi, Apache Spark.

Useful Links

For additional information, visit the OpenNLP Home Page

You can use OpenNLP with any language, demo models are provided here.

The models are fully compatible with the latest release, they can be used for testing or getting started.

[!NOTE]
Please train your own models for all other use cases.

Documentation, including JavaDocs, code usage and command-line interface examples are available here

For recent news, updates and topics, you can:
- join the regular mailing lists, - follow the project's Bluesky social media channel, or - join the Slack channel (available to people with an @apache.org email address or upon invitation).

Please, also check the Stack Overflow community's OpenNLP questions and answers.

Overview

Currently, the library has different modules:

  • opennlp-api : The public API defining core Apache OpenNLP interfaces and abstractions.
  • opennlp-runtime : The core classes shared across Apache OpenNLP components.
  • opennlp-ml-commons : Common utilities and shared functionality for ML implementations.
  • opennlp-ml-maxent : Maximum Entropy (MaxEnt) machine learning implementation.
  • opennlp-ml-bayes : Naive Bayes machine learning implementation.
  • opennlp-ml-perceptron : Perceptron-based machine learning implementation.
  • opennlp-ml-libsvm : Support Vector Machine (SVM) based text classification via zlibsvm.
  • opennlp-dl : Apache OpenNLP adapter for ONNX models using the onnxruntime dependency.
  • opennlp-dl-gpu : Replaces onnxruntime with the onnxruntime_gpu dependency to support GPU acceleration.
  • opennlp-model-resolver : Classes for discovering and loading Apache OpenNLP models from the classpath.
  • opennlp-formats : Support for reading and writing various NLP training and data formats.
  • opennlp-cli : The command-line tools for training, evaluating, and running models.
  • opennlp-tools : The full end-user toolkit with all core components and utilities in its executable form.
  • opennlp-morfologik : Extension module providing Morfologik-based dictionary and stemming support.
  • opennlp-spellcheck : Extension module providing SymSpell-based, language-agnostic spell correction.
  • opennlp-uima : Extension module providing a set of Apache UIMA annotators.
  • opennlp-sandbox : Other projects in progress reside in the sandbox.

Getting Started

You can import the core toolkit directly from Maven or Gradle:

Maven

<dependency>
    <groupId>org.apache.opennlp</groupId>
    <artifactId>opennlp-runtime</artifactId>
    <version>${opennlp.version}</version>
</dependency>

<dependency>
    <groupId>org.apache.opennlp</groupId>
    <artifactId>opennlp-model-resolver</artifactId>
    <version>${opennlp.version}</version>
</dependency>

Note: opennlp-runtime ships with the MaxEnt ML implementation by default. If you need other ML implementations, please add the corresponding dependencies as well.

Gradle

compile group: "org.apache.opennlp", name: "opennlp-runtime", version: "${opennlp.version}"
compile group: "org.apache.opennlp", name: "opennlp-model-resolver", version: "${opennlp.version}"

For more details please check our documentation

Migrating from 2.x to 3.x

The 3.x release line of Apache OpenNLP introduces no known breaking changes but modularizes the project for better usage as a library and to support future extensibility. The core API remains stable and compatible with 2.x, but the project structure has been reorganized into multiple modules.

That means, that you can continue to use the previous opennlp-tools artifact as a dependency. However, we strongly recommend to switch to the new modular structure and import only the components you need, which will result in a smaller dependency footprint.

Only opennlp-runtime needs to be added as a dependency, and you can add additional modules (e.g. opennlp-ml-maxent, opennlp-model-resolver, etc.) as required by your project. For users of the traditional CLI toolkit, nothing changes with the 3.x release line. CLI usage remains stable as described in the project's dev manual.

Thread safety

Starting with 3.0.0, the core *ME classes (POSTaggerME, TokenizerME, SentenceDetectorME, ChunkerME, LemmatizerME, NameFinderME) are thread safe and a single instance can be shared across threads. This eliminates the need to pool or recreate ME instances per thread. The legacy ThreadSafe*ME wrappers from 2.x still work but are now deprecated; existing code does not need to change to upgrade.

Head's up

The Apache OpenNLP team is planning to change the package namespace from opennlp to org.apache.opennlp in a future release (potentially 4.x). This change will be made to align with standard Java package naming conventions and to avoid potential conflicts with other libraries.

In addition, the Apache OpenNLP team raised the minimal Java version to JDK 21+ for the 3.0.0 release to take advantage of the latest language features and improvements.

Branches and Merging Strategy

To support ongoing development and stable maintenance of Apache OpenNLP, the project follows a dual-branch model:

Branch overview

  • main: Development branch for version 3.0 and beyond. All feature development and 3.x releases occur here. Minimum Java level: 21.
  • opennlp-2.x: Maintains the stable 2.x release line. This branch will receive selective updates and patch releases. Minimum Java level: 17.

Workflow summary

  • Feature development
  • New features targeting versions 3.0+ are developed on feature branches off main and merged into main.
  • Bug fixes and dependency updates
  • Relevant fixes or dependency updates from main may be cherry-picked into opennlp-2.x as needed.
  • Releases
  • 3.x releases are made from the main branch.
  • 2.x releases are made from the opennlp-2.x branch.
  • Release tags
  • Release tags are applied directly to the appropriate version branch (main for 3.x or opennlp-2.x for 2.x).
  • The presence of a version branch does not affect the tagging or visibility of releases.

Building OpenNLP

For the main branch, at least JDK 21 and Maven 3.9.x are required to build the library.

After cloning the repository go into the destination directory and run:

mvn install

Additional Development Information

Contributing

The Apache OpenNLP project is developed by volunteers and is always looking for new contributors to work on all parts of the project. Every contribution is welcome and needed to make it better. A contribution can be anything from a small documentation typo fix to a new component.

If you would like to get involved please follow the instructions here

Extension points exported contracts — how you extend this code

POSModelResource (Interface)
A resource encapsulating an OpenNLP POSModel which can be shared between analysis engines and loaded via [12 implementers]
opennlp-extensions/opennlp-uima/src/main/java/opennlp/uima/postag/POSModelResource.java
ContextGenerator (Interface)
Represents a generator of contexts for maxent decisions. [25 implementers]
opennlp-core/opennlp-ml/opennlp-ml-maxent/src/main/java/opennlp/tools/ml/maxent/ContextGenerator.java
ClassPathModelProvider (Interface)
A provider for obtaining pre-trained OpenNLP BaseModel models from an application's classpath. Providing mod [8 implementers]
opennlp-core/opennlp-model-resolver/src/main/java/opennlp/tools/models/ClassPathModelProvider.java
POSContextGenerator (Interface)
Interface for a BeamSearchContextGenerator used in POS tagging. [27 implementers]
opennlp-api/src/main/java/opennlp/tools/postag/POSContextGenerator.java
EditDistance (Interface)
Computes the edit distance between two character sequences with an upper bound. Implementations must be Unicode-awar [4 …
opennlp-extensions/opennlp-spellcheck/src/main/java/opennlp/spellcheck/distance/EditDistance.java
Masc (Interface)
A simple marker interface for classes that support or refer to the #MASC_FORMAT. [4 implementers]
opennlp-core/opennlp-formats/src/main/java/opennlp/tools/formats/masc/Masc.java
EntryInserter (Interface)
(no doc) [2 implementers]
opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/dictionary/serializer/EntryInserter.java
ParserModelResource (Interface)
A resource encapsulating an OpenNLP ParserModel which can be shared between analysis engines and loaded [12 implementers]
opennlp-extensions/opennlp-uima/src/main/java/opennlp/uima/parser/ParserModelResource.java

Core symbols most depended-on inside this repo

get
called by 1265
opennlp-api/src/main/java/opennlp/tools/util/wordvector/WordVectorTable.java
read
called by 609
opennlp-api/src/main/java/opennlp/tools/util/ObjectStream.java
put
called by 598
opennlp-api/src/main/java/opennlp/tools/util/Parameters.java
size
called by 545
opennlp-api/src/main/java/opennlp/tools/util/wordvector/WordVectorTable.java
add
called by 539
opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/ngram/NGramModel.java
slice_from
called by 389
opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/stemmer/snowball/SnowballProgram.java
length
called by 382
opennlp-api/src/main/java/opennlp/tools/util/Span.java
slice_del
called by 308
opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/stemmer/snowball/SnowballProgram.java

Shape

Method 6,995
Class 1,332
Interface 209
Enum 24

Languages

Java100%

Modules by API surface

opennlp-core/opennlp-runtime/src/test/java/opennlp/tools/stopword/DictionaryStopwordFilterTest.java116 symbols
opennlp-core/opennlp-cli/src/main/java/opennlp/tools/cmdline/FineGrainedReportListener.java80 symbols
opennlp-api/src/main/java/opennlp/tools/parser/Parse.java62 symbols
opennlp-core/opennlp-runtime/src/test/java/opennlp/tools/namefind/BilouCodecTest.java45 symbols
opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/stemmer/snowball/turkishStemmer.java45 symbols
opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/stemmer/snowball/greekStemmer.java38 symbols
opennlp-eval-tests/src/test/java/opennlp/tools/eval/Conll02NameFinderEval.java34 symbols
opennlp-eval-tests/src/test/java/opennlp/spellcheck/eval/SpellCheckerEval.java32 symbols
opennlp-core/opennlp-ml/opennlp-ml-libsvm/src/test/java/opennlp/tools/ml/libsvm/doccat/DocumentCategorizerSVMTest.java32 symbols
opennlp-core/opennlp-formats/src/main/java/opennlp/tools/formats/ad/ADSentenceStream.java32 symbols
opennlp-core/opennlp-runtime/src/test/java/opennlp/tools/namefind/BilouNameFinderSequenceValidatorTest.java31 symbols
opennlp-core/opennlp-ml/opennlp-dl/src/test/java/opennlp/dl/namefinder/NameFinderDLTest.java30 symbols

For agents

$ claude mcp add opennlp \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page