Class DictionaryCatalog

java.lang.Object
opennlp.tools.util.DictionaryCatalog

public final class DictionaryCatalog extends Object
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
  • Field Details

    • REMOTE_DOWNLOAD_PROPERTY

      public static final String REMOTE_DOWNLOAD_PROPERTY
      System property that must be true before a catalog entry may be fetched. Direct ResourceInstaller calls do not require it: there the caller already supplied the URI and digest.
      See Also:
  • Method Details

    • load

      public static DictionaryCatalog load(InputStream in) throws IOException
      Loads a catalog from a properties stream.
      Parameters:
      in - The properties content. Must not be null.
      Returns:
      The catalog. Never null.
      Throws:
      IOException - Thrown if reading fails.
      IllegalArgumentException - Thrown if in is null.
    • ids

      public Set<String> ids()
      Returns an unmodifiable set of catalog entry ids.
      Returns:
      an unmodifiable set of catalog entry ids
    • get

      public DictionaryCatalog.Entry get(String id) throws IOException
      Looks up one catalog entry.
      Parameters:
      id - The entry id, for example mecab.ipadic.
      Returns:
      The entry. Never null.
      Throws:
      IOException - Thrown if the entry is incomplete or invalid.
      IllegalArgumentException - Thrown if id is null.
    • install

      public void install(String id, Path targetDirectory) throws IOException
      Installs a catalog entry into targetDirectory under ResourceInstaller.Limits.DEFAULT when REMOTE_DOWNLOAD_PROPERTY is true, as described in install(String, Path, boolean, ResourceInstaller.Limits).
      Parameters:
      id - The entry id. Must not be null.
      targetDirectory - The directory to install into; created when absent. Must not be null.
      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 is null.
    • install

      public void install(String id, Path targetDirectory, boolean remoteDownloadEnabled, ResourceInstaller.Limits limits) throws IOException
      Installs a catalog entry into targetDirectory when remote downloads are enabled. The entry is fetched, digest-verified, and unpacked by ResourceInstaller: an archive expands into the directory, and a plain file is stored under the entry's <id>.filename value when the catalog sets one, or under the file name of its source URI otherwise.
      Parameters:
      id - The entry id. Must not be null.
      targetDirectory - The directory to install into; created when absent. Must not be null.
      remoteDownloadEnabled - Whether the caller allows the entry to be fetched; false rejects the installation.
      limits - The limits the installation runs under. Must not be null.
      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 if id, targetDirectory, or limits is null.