Package opennlp.tools.util
Class DictionaryCatalog
java.lang.Object
opennlp.tools.util.DictionaryCatalog
Opt-in catalog of remote dictionary archives and companion files, loaded from
application-supplied properties containing URLs and SHA-512 digests. Fetching an
entry requires
REMOTE_DOWNLOAD_PROPERTY to be true.- Since:
- 3.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordOne catalog entry with a URI and the SHA-512 digest of its bytes. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate final Propertiesstatic final StringSystem property that must betruebefore a catalog entry may be fetched.private static final Stringprivate static final String -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateDictionaryCatalog(Properties properties) Initializes a catalog from loaded properties. -
Method Summary
Modifier and TypeMethodDescriptionLooks up one catalog entry.ids()Returns an unmodifiable set of catalog entry ids.voidInstalls a catalog entry intotargetDirectoryunderResourceInstaller.Limits.DEFAULTwhenREMOTE_DOWNLOAD_PROPERTYistrue, as described ininstall(String, Path, boolean, ResourceInstaller.Limits).voidinstall(String id, Path targetDirectory, boolean remoteDownloadEnabled, ResourceInstaller.Limits limits) Installs a catalog entry intotargetDirectorywhen remote downloads are enabled.static DictionaryCatalogload(InputStream in) Loads a catalog from a properties stream.
-
Field Details
-
URL_SUFFIX
- See Also:
-
SHA512_SUFFIX
- See Also:
-
FILENAME_SUFFIX
- See Also:
-
REMOTE_DOWNLOAD_PROPERTY
System property that must betruebefore a catalog entry may be fetched. DirectResourceInstallercalls do not require it: there the caller already supplied the URI and digest.- See Also:
-
properties
-
-
Constructor Details
-
DictionaryCatalog
Initializes a catalog from loaded properties.- Parameters:
properties- The catalog properties.
-
-
Method Details
-
load
Loads a catalog from a properties stream.- Parameters:
in- The properties content. Must not benull.- Returns:
- The catalog. Never
null. - Throws:
IOException- Thrown if reading fails.IllegalArgumentException- Thrown ifinisnull.
-
ids
Returns an unmodifiable set of catalog entry ids.- Returns:
- an unmodifiable set of catalog entry ids
-
get
Looks up one catalog entry.- Parameters:
id- The entry id, for examplemecab.ipadic.- Returns:
- The entry. Never
null. - Throws:
IOException- Thrown if the entry is incomplete or invalid.IllegalArgumentException- Thrown ifidisnull.
-
install
Installs a catalog entry intotargetDirectoryunderResourceInstaller.Limits.DEFAULTwhenREMOTE_DOWNLOAD_PROPERTYistrue, as described ininstall(String, Path, boolean, ResourceInstaller.Limits).- Parameters:
id- The entry id. Must not benull.targetDirectory- The directory to install into; created when absent. Must not benull.- Throws:
IOException- Thrown if the property is not enabled, the entry is missing, the download fails verification, or the target already contains an installed file.IllegalArgumentException- Thrown if a parameter isnull.
-
install
public void install(String id, Path targetDirectory, boolean remoteDownloadEnabled, ResourceInstaller.Limits limits) throws IOException Installs a catalog entry intotargetDirectorywhen remote downloads are enabled. The entry is fetched, digest-verified, and unpacked byResourceInstaller: an archive expands into the directory, and a plain file is stored under the entry's<id>.filenamevalue when the catalog sets one, or under the file name of its source URI otherwise.- Parameters:
id- The entry id. Must not benull.targetDirectory- The directory to install into; created when absent. Must not benull.remoteDownloadEnabled- Whether the caller allows the entry to be fetched;falserejects the installation.limits- The limits the installation runs under. Must not benull.- Throws:
IOException- Thrown if remote downloads are not enabled, the entry is missing, a limit is exceeded, the download fails verification, or the target already contains an installed file.IllegalArgumentException- Thrown ifid,targetDirectory, orlimitsisnull.
-