Class MecabDictionaryInstaller

java.lang.Object
opennlp.tools.tokenize.lattice.MecabDictionaryInstaller

public final class MecabDictionaryInstaller extends Object
Fetches and unpacks a MeCab-format dictionary archive into a local directory, so the dictionary is acquired by the user at install time and never ships with this library. No dictionary data is bundled. Fetching, verification, and unpacking are done by ResourceInstaller under ResourceInstaller.Limits.DEFAULT, including startup property overrides. An http or https archive requires an expected checksum, and the ustar, pax, and GNU tar formats are all read. Catalog installs are opt-in via installFromCatalog(DictionaryCatalog, String, Path).

Only the dictionary payload is installed: the *.csv lexicon files and *.def definition files that a MecabDictionary reads, plus the dicrc configuration file distributions ship alongside them, taken from the archive root only (at most one leading directory deep). Deeper entries are skipped: mecab-ko-dic, for example, nests user-dic templates whose numeric fields are empty because they are input for mecab-dict-index, not loadable lexicon data. Installed files are flattened to their base names. A file whose base name already exists in the target is not replaced, so it must be removed before refreshing a dictionary. The archive unpacks into a hidden scratch directory beneath the target, on the target's filesystem, which is removed when the installation ends.

Since:
3.0.0
  • Method Details

    • install

      public static int install(URI archive, Path targetDirectory) throws IOException
      Unpacks a local file: archive URI. Any other scheme requires install(URI, Path, String) with an expected checksum.
      Parameters:
      archive - The archive location, a gzip-compressed tar. Must not be null.
      targetDirectory - The directory to unpack into; created when absent. Must not be null.
      Returns:
      The number of dictionary files installed.
      Throws:
      IOException - Thrown if reading or writing fails, the archive contains no dictionary file, an installation limit is exceeded, or the target already contains one of the files.
      IllegalArgumentException - Thrown if a parameter is null or archive does not use the file scheme.
    • install

      public static int install(URI archive, Path targetDirectory, String expectedChecksum) throws IOException
      Downloads a dictionary archive when needed, verifies its checksum, and unpacks it through ResourceInstaller.install(URI, Path, String). A file: URI may omit the checksum.
      Parameters:
      archive - The archive location, a gzip-compressed tar. Must not be null.
      targetDirectory - The directory to unpack into; created when absent. Must not be null.
      expectedChecksum - The expected digest of the archive bytes as a hex string, 64 characters for SHA-256 or 128 for SHA-512. Required for an http or https source; pass null to skip verification for a file source.
      Returns:
      The number of dictionary files installed.
      Throws:
      IOException - Thrown if fetching, verification, reading, or writing fails, the archive contains no dictionary file, an installation limit is exceeded, or the target already contains one of the files.
      IllegalArgumentException - Thrown if a parameter is null, the URI is not supported by ResourceInstaller, or an http or https source has no checksum.
    • installFromCatalog

      public static int installFromCatalog(DictionaryCatalog catalog, String dictionaryId, Path targetDirectory) throws IOException
      Downloads a dictionary named in an application-supplied DictionaryCatalog and unpacks it. Requires -Dopennlp.download.remote=true.
      Parameters:
      catalog - The application-supplied catalog. Must not be null.
      dictionaryId - The catalog id, for example mecab.ipadic or mecab.ko-dic. Must not be null.
      targetDirectory - The directory to unpack into; created when absent. Must not be null.
      Returns:
      The number of dictionary files installed.
      Throws:
      IOException - Thrown if the catalog entry is missing, remote downloads are disabled, or install fails.
      IllegalArgumentException - Thrown if a parameter is null.