Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OPENNLP-1618 - AbstractDL does not release Ort Resources #662

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions opennlp-dl/src/main/java/opennlp/dl/AbstractDL.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/**
* Base class for OpenNLP deep-learning classes using ONNX Runtime.
*/
public abstract class AbstractDL {
public abstract class AbstractDL implements AutoCloseable {

public static final String INPUT_IDS = "input_ids";
public static final String ATTENTION_MASK = "attention_mask";
Expand All @@ -50,7 +50,6 @@ public abstract class AbstractDL {
*
* @param vocabFile The vocabulary file.
* @return A map of vocabulary words to integer IDs.
*
* @throws IOException Thrown if the vocabulary file cannot be opened or read.
*/
public Map<String, Integer> loadVocab(final File vocabFile) throws IOException {
Expand All @@ -66,4 +65,19 @@ public Map<String, Integer> loadVocab(final File vocabFile) throws IOException {
return vocab;
}

/**
* Closes this resource, relinquishing any underlying resources.
*
* @throws Exception If it failed to close.
*/
@Override
public void close() throws Exception {
if (session != null) {
session.close();
}
if (env != null) {
env.close();
}
}

}
Loading