Class DirectoryModelFinder

java.lang.Object
opennlp.tools.models.AbstractClassPathModelFinder
opennlp.tools.models.dir.DirectoryModelFinder
All Implemented Interfaces:
ClassPathModelFinder

public class DirectoryModelFinder extends AbstractClassPathModelFinder implements ClassPathModelFinder
The DirectoryModelFinder class is responsible for finding model files in a given directory on the classpath.

This class allows searching for models based on wildcard patterns, either in plain directory structures or within JAR files. The search can be performed recursively depending on the specified configuration.

Usage:

  • Provide the prefix for models to be found in JAR files using the jarModelPrefix parameter.
  • Specify the directory to search and whether to enable recursive scanning.
  • The class supports resolving both direct file matches and entries within JAR archives.
See Also:
  • Field Details

    • logger

      private static final org.slf4j.Logger logger
    • directory

      private final Path directory
    • recursive

      private final boolean recursive
  • Constructor Details

    • DirectoryModelFinder

      public DirectoryModelFinder(String jarModelPrefix, Path directory, boolean recursive)
      Instantiates a new DirectoryModelFinder with the specified parameters.
      Parameters:
      jarModelPrefix - The prefix for identifying model files in JAR archives; may be null. If it is null, ClassPathModelFinder.OPENNLP_MODEL_JAR_PREFIX is used.
      directory - The root directory to scan from for model files; must not be null.
      recursive - true if the search should include subdirectories, false otherwise.
      Throws:
      IllegalArgumentException - Thrown if directory is null.
  • Method Details

    • getContext

      protected Object getContext()
      Specified by:
      getContext in class AbstractClassPathModelFinder
      Returns:
      Always null as it is not needed for the directory case.
    • getMatchingURIs

      protected List<URI> getMatchingURIs(String wildcardPattern, Object context)
      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.
      Returns:
      A list of matching classpath URIs.
    • getDirectoryContent

      private List<URL> getDirectoryContent()