Package opennlp.tools.models
Class ClassPathModelLoader
java.lang.Object
opennlp.tools.models.ClassPathModelLoader
Responsible for loading OpenNLP models from the classpath via
entries.
If models could be loaded successfully, those are provided as model references
or as instances of the specified ModelType.- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) <T extends BaseModel>
T(package private) <T extends BaseModel>
Tload(ClassPathModelEntry entry) Loads aClassPathModelfrom aClassPathModelEntry
-
Constructor Details
-
ClassPathModelLoader
public ClassPathModelLoader()
-
-
Method Details
-
load
Loads aClassPathModelfrom aClassPathModelEntry- Parameters:
entry- A validClassPathModelEntry, it must not benull. Moreover, it is validated that thebinary dataandmeta-dataare notnull.- Returns:
- A
ClassPathModelcontaining the model resources. - Throws:
IOException- Thrown if something went wrong during reading resources from the classpath.
-
load
<T extends BaseModel> T load(Set<ClassPathModelEntry> classPathEntries, String lang, ModelType type, Class<T> modelType) throws IOException - Parameters:
classPathEntries- A non-empty set ofcandidatesto find a matching model in. Must not benull. If it is empty, the result will benull.lang- The language code of the requested model. Ifnullor empty, the result will benullas well.type- TheModelTypeto select the model variant. It must not benull.modelType- The class of model type parameterClassPathModelLoaderto create an instance of.- Returns:
- An model instance of type
ClassPathModelLoader, ornullif no match was found for the specified parameters. - Throws:
IllegalArgumentException- Thrown if parameters were invalid.ClassPathLoaderException- Thrown ifClassPathModelLoadercould not be instantiated correctly.IOException- Thrown if something went wrong during reading resources from the classpath.
-
load
<T extends BaseModel> T load(Set<ClassPathModelEntry> classPathEntries, String lang, String type, Class<T> modelType) throws IOException - Parameters:
classPathEntries- A non-empty set ofcandidatesto find a matching model in. Must not benull. If it is empty, the result will benull.lang- The language code of the requested model. Ifnullor empty, the result will benullas well.type- The type string to narrow down the model variant. Note: Custom naming patterns can be applied here, as thetypefragment will be used for a 'contains' check internally.modelType- The class of model type parameterClassPathModelLoaderto create an instance of. It must not benull.- Returns:
- An model instance of type
ClassPathModelLoader, ornullif no match was found for the specified parameters. - Throws:
IllegalArgumentException- Thrown if parameters were invalid.ClassPathLoaderException- Thrown ifClassPathModelLoadercould not be instantiated correctly.IOException- Thrown if something went wrong during reading resources from the classpath.
-