Class ClassgraphModelFinder

java.lang.Object
opennlp.tools.models.AbstractClassPathModelFinder
opennlp.tools.models.classgraph.ClassgraphModelFinder
All Implemented Interfaces:
ClassPathModelFinder

public class ClassgraphModelFinder extends AbstractClassPathModelFinder implements ClassPathModelFinder
Enables the detection of OpenNLP models in the classpath via Classgraph.

By default, this implementation will search for JAR files starting with "opennlp-models-*". This search mask can be adjusted by using the one argument constructor. Wildcard search is supported by using asterisk symbol. Masks follow the wildcard rules of ClassGraph, not the rules of AbstractClassPathModelFinder.matchesWildcard(java.net.URL, String).

See Also:
  • Constructor Details

    • ClassgraphModelFinder

      public ClassgraphModelFinder()
      By default, it scans for "opennlp-models-*.jar".
    • ClassgraphModelFinder

      public ClassgraphModelFinder(String modelJarPrefix)
      Parameters:
      modelJarPrefix - The leafnames of the jars that should be scanned (e.g. "opennlp.jar"). May contain a wildcard glob ("opennlp-*.jar"). It must not be null.
      Throws:
      IllegalArgumentException - Thrown if modelJarPrefix is null.
  • Method Details

    • getContext

      protected Object getContext()
      Specified by:
      getContext in class AbstractClassPathModelFinder
      Returns:
      A ScanResult ready for consumption.
    • getMatchingURIs

      protected List<URI> getMatchingURIs(String wildcardPattern, Object context)
      Attempts to obtain URIs from the classpath for the specified wildcardPattern and context.
      Specified by:
      getMatchingURIs in class AbstractClassPathModelFinder
      Parameters:
      wildcardPattern - The pattern to use for scanning. Must not be null.
      context - An object holding context information. It might be null.
      Returns:
      A list of matching classpath URIs which may be empty if nothing is found.