Class SimpleClassPathModelFinder

java.lang.Object
opennlp.tools.models.AbstractClassPathModelFinder
opennlp.tools.models.simple.SimpleClassPathModelFinder
All Implemented Interfaces:
ClassPathModelFinder

public class SimpleClassPathModelFinder extends AbstractClassPathModelFinder implements ClassPathModelFinder
Enables the detection of OpenNLP models in the classpath via JDK classes By default, this class will search for JAR files starting with "opennlp-models-*". This wildcard pattern can be adjusted by using the alternative constructor of this class.
See Also:
  • Field Details

    • CLASSPATH_SEPARATOR_WINDOWS

      private static final char CLASSPATH_SEPARATOR_WINDOWS
      See Also:
    • CLASSPATH_SEPARATOR_UNIX

      private static final char CLASSPATH_SEPARATOR_UNIX
      See Also:
  • Constructor Details

    • SimpleClassPathModelFinder

      public SimpleClassPathModelFinder()
    • SimpleClassPathModelFinder

      public SimpleClassPathModelFinder(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:
      Always null as it is not needed for the simple case.
    • getMatchingURIs

      protected List<URI> getMatchingURIs(String wildcardPattern, Object context)
      Description copied from class: AbstractClassPathModelFinder
      Retrieve matching classpath URIs for the given wildcardPattern.
      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. It is unused within this implementation.
      Returns:
      A list of matching classpath URIs. It may be an empty list if nothing is found.
    • getClassPathElements

      private List<URL> getClassPathElements()
      Attempts to obtain URLs from the classpath in the following order:

      1. Try to see if we have a URLClassLoader available in the current thread.
      2. Try to obtain URLs via the build in classloader via reflections.
        (requires --add-opens java.base/jdk.internal.loader=ALL-UNNAMED as JVM argument)
      3. Try to use the bootstrap classpath via java.class.path.
      Returns:
      A list of URLs within the classpath.
    • getClassPathUrlsFromSystemProperty

      private List<URL> getClassPathUrlsFromSystemProperty()
    • splitClassPath

      String[] splitClassPath(String classPath, boolean isWindows)
      Splits classPath on the platform's path separator, ; on Windows and : elsewhere. Empty entries, from leading, trailing, or repeated separators, are skipped, since they name no jar file.
      Parameters:
      classPath - The class path value to split. Must not be null.
      isWindows - true to split on ;, false to split on :.
      Returns:
      The non-empty class path entries in order.
      Throws:
      IllegalArgumentException - Thrown if classPath is null.
    • getURLs

      private URL[] getURLs(ClassLoader classLoader)