Package opennlp.tools.models

# Class DefaultClassPathModelProvider

java.lang.Object
opennlp.tools.models.DefaultClassPathModelProvider

All Implemented Interfaces:
  `ClassPathModelProvider`

public class DefaultClassPathModelProvider extends Object implements ClassPathModelProvider
A default implementation of `ClassPathModelProvider` which by default relies on `SimpleClassPathModelFinder` to scan for models in the current classpath.

See Also:
  - `ClassPathModelFinder`
  - `ClassPathModelLoader`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DefaultClassPathModelProvider()`
  Instantiates a `DefaultClassPathModelProvider` with a `SimpleClassPathModelFinder` and uses a default `ClassPathModelLoader`.
  `DefaultClassPathModelProvider(ClassPathModelFinder finder, ClassPathModelLoader loader)`
  Instantiates a `DefaultClassPathModelProvider` with the specified `modelJarPattern`, a `model finder` and a `model loader` instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `<T extends opennlp.tools.util.model.BaseModel>
  T`
  `load(String lang, opennlp.tools.models.ModelType type, Class<T> modelType)`
  Restores a `model` among all classpath models at runtime according to the specified parameters `lang` and `type`.
  `<T extends opennlp.tools.util.model.BaseModel>
  T`
  `load(String lang, opennlp.tools.models.ModelType type, Class<T> modelType, boolean reloadCache)`
  Restores a `model` among all classpath models at runtime according to the specified parameters `lang` and `type`.

  ### Methods inherited from class java.lang.Object

  `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### DefaultClassPathModelProvider

    public DefaultClassPathModelProvider()
    Instantiates a `DefaultClassPathModelProvider` with a `SimpleClassPathModelFinder` and uses a default `ClassPathModelLoader`. By default, it scans for the `ClassPathModelFinder.OPENNLP_MODEL_JAR_PREFIX` pattern for available model jars.

  - ### DefaultClassPathModelProvider

    public DefaultClassPathModelProvider(ClassPathModelFinder finder, ClassPathModelLoader loader)
    Instantiates a `DefaultClassPathModelProvider` with the specified `modelJarPattern`, a `model finder` and a `model loader` instance.
    Parameters:
      `finder` - The `ClassPathModelFinder` instance to use for this provider. It must not be `null`.
      `loader` - The `ClassPathModelLoader` instance to use for this provider. It must not be `null`.
    Throws:
      `IllegalArgumentException` - Thrown if one of the specified parameters were invalid.

- ## Method Details

  - ### load

    public <T extends opennlp.tools.util.model.BaseModel> T load(String lang, opennlp.tools.models.ModelType type, Class<T> modelType) throws IOException
    Restores a `model` among all classpath models at runtime according to the specified parameters `lang` and `type`.
    Specified by:
      `load` in interface `ClassPathModelProvider`
    Parameters:
      `lang` - The ISO language code of the requested model. If `null` or empty, the result will be `null` as well.
      `type` - The type string to narrow down the model variant. Note: Custom naming patterns can be applied here, as the `type` fragment will be used for a 'contains' check internally.
      `modelType` - The class of model type parameter `ClassPathModelProvider` to create an instance of.
    Returns:
      An model instance of type `ClassPathModelProvider`, or `null` if no match was found for the specified parameters.
    Throws:
      `IOException` - Thrown if something went wrong during reading resources from the classpath.

  - ### load

    public <T extends opennlp.tools.util.model.BaseModel> T load(String lang, opennlp.tools.models.ModelType type, Class<T> modelType, boolean reloadCache) throws IOException
    Restores a `model` among all classpath models at runtime according to the specified parameters `lang` and `type`.
    Specified by:
      `load` in interface `ClassPathModelProvider`
    Parameters:
      `lang` - The ISO language code of the requested model. If `null` or empty, the result will be `null` as well.
      `type` - The type of model to specifiy the model variant.
      `modelType` - The class of model type parameter `ClassPathModelProvider` to create an instance of.
      `reloadCache` - `true`, if the internal cache of the `ClassPathModelFinder` should explicitly be reloaded, `false` otherwise.
    Returns:
      An model instance of type `ClassPathModelProvider`, or `null` if no match was found for the specified parameters.
    Throws:
      `IOException` - Thrown if something went wrong during reading resources from the classpath.