Package opennlp.dl

Class AbstractDL

java.lang.Object
opennlp.dl.AbstractDL
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
DocumentCategorizerDL, NameFinderDL, SentenceVectorsDL

public abstract class AbstractDL extends Object implements AutoCloseable
Base class for OpenNLP deep-learning classes using ONNX Runtime.
  • Field Details

  • Method Details

    • loadVocab

      public Map<String,Integer> loadVocab(File vocabFile) throws IOException
      Loads a vocabulary File from disk. Supports both plain text files (one token per line) and simple JSON vocabulary files mapping tokens to integer IDs. JSON support is intentionally limited to the HuggingFace vocabulary shape; it is not a general-purpose JSON parser.
      Parameters:
      vocabFile - The vocabulary file.
      Returns:
      A map of vocabulary words to IDs.
      Throws:
      IOException - Thrown if the vocabulary file cannot be opened or read.
    • close

      public void close() throws ai.onnxruntime.OrtException
      Closes the ONNX OrtSession owned by this instance.

      The OrtEnvironment is deliberately not closed: OrtEnvironment.getEnvironment() returns a process-wide singleton shared by every deep-learning component, so closing it here would tear down the environment other live components still depend on.

      This method is idempotent: calling close() more than once, or calling it on a never-used but successfully constructed instance, is a no-op after the first successful close attempt. The underlying OrtSession.close() is only invoked once.

      Specified by:
      close in interface AutoCloseable
      Throws:
      ai.onnxruntime.OrtException - Thrown if the close attempt fails in the native layer.