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 after checking that remote catalog downloads are enabled. The entry is fetched, digest-verified, and unpacked by ResourceInstaller.install(URI, Path, String): an archive expands into the directory, and a plain file is stored under its source name.
      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.