This is an automated email from the ASF dual-hosted git repository. mawiesne pushed a commit to branch OPENNLP-1791-Document-the-use-of-ClassPathModelProvider-in-dev-manual in repository https://gitbox.apache.org/repos/asf/opennlp.git
commit 6cda164bea4c9f96032df35f5bedfa05708c6ae4 Author: Martin Wiesner <[email protected]> AuthorDate: Fri Dec 26 18:59:23 2025 +0100 OPENNLP-1791: Document the use of ClassPathModelProvider in dev manual --- opennlp-docs/src/docbkx/model-loading.xml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/opennlp-docs/src/docbkx/model-loading.xml b/opennlp-docs/src/docbkx/model-loading.xml index aec161cd..b4e0f37a 100644 --- a/opennlp-docs/src/docbkx/model-loading.xml +++ b/opennlp-docs/src/docbkx/model-loading.xml @@ -95,6 +95,25 @@ for(ClassPathModelEntry entry : models) { }]]> </programlisting> + Moreover, certain OpenNLP models can be obtained via a + <emphasis>ClassPathModelProvider</emphasis>, such as OpenNLP's + built-in <emphasis>DefaultClassPathModelProvider</emphasis> class. + It allows direct use of models available under a certain locale, given + that those are present in the classpath and can be loaded. + + <programlisting language="java"> + <![CDATA[ +final ClassPathModelProvider provider = new DefaultClassPathModelProvider(finder, loader); +// Here: SentenceModel, other model types accordingly +final SentenceModel sm = provider.load("en", opennlp.tools.models.ModelType.SENTENCE_DETECTOR, SentenceModel.class); +if(sm != null) { + // do something with the (sentence) model +}]]> + </programlisting> + + In the above example, the finder and loader objects can be created or re-used as shown in the + previous code example. + </para> </section>
