You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by ma...@apache.org on 2026/10/03 16:00:34 UTC
(opennlp) branch main updated: Minor: Mark AbstractDL chunking and normalization helpers @Internal (#1368)
This is an automated email from the ASF dual-hosted git repository.
mawiesne pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opennlp.git
The following commit(s) were added to refs/heads/main by this push:
new c4c596c43 Minor: Mark AbstractDL chunking and normalization helpers @Internal (#1368)
c4c596c43 is described below
commit c4c596c435ee2f1fd039e9693e65c4d0a469340a
Author: Richard Zowalla <13...@users.noreply.github.com>
AuthorDate: Sat Oct 3 18:00:28 2026 +0200
Minor: Mark AbstractDL chunking and normalization helpers @Internal (#1368)
---
.../src/main/java/opennlp/dl/AbstractDL.java | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/AbstractDL.java b/opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/AbstractDL.java
index 25ff94ce9..781fb3ed2 100644
--- a/opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/AbstractDL.java
+++ b/opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/AbstractDL.java
@@ -34,6 +34,7 @@ import ai.onnxruntime.OrtEnvironment;
import ai.onnxruntime.OrtException;
import ai.onnxruntime.OrtSession;
+import opennlp.tools.commons.Internal;
import opennlp.tools.tokenize.SubwordPiece;
import opennlp.tools.tokenize.SubwordTokenizer;
import opennlp.tools.tokenize.WordpieceEncoder;
@@ -62,6 +63,13 @@ public abstract class AbstractDL implements AutoCloseable {
private final AtomicBoolean closed = new AtomicBoolean();
+ /**
+ * A half-open range of token indices covered by one chunk.
+ *
+ * @param start The inclusive index of the first token of the chunk.
+ * @param end The exclusive index after the last token of the chunk.
+ */
+ @Internal(since = "3.0.0")
protected record ChunkRange(int start, int end) {
}
@@ -73,6 +81,7 @@ public abstract class AbstractDL implements AutoCloseable {
* @param start The inclusive character offset of the chunk in the source text.
* @param end The exclusive character offset of the chunk in the source text.
*/
+ @Internal(since = "3.0.0")
protected record TextChunk(String text, int start, int end) {
}
@@ -373,12 +382,13 @@ public abstract class AbstractDL implements AutoCloseable {
/**
* Unicode-aware whitespace. Input is tokenized on the full Unicode {@code White_Space} set
- * rather than the six ASCII characters Java's {@code \s} recognizes, and the same class is
- * reused by subclasses that need to match against whitespace in the source text.
+ * rather than the six ASCII characters Java's {@code \s} recognizes.
*/
+ @Internal(since = "3.0.0")
protected static final CharClass WHITESPACE = CharClass.whitespace();
/** Unicode dashes (excluding the mathematical minus signs), used for optional input folding. */
+ @Internal(since = "3.0.0")
protected static final CharClass DASHES = CharClass.dashes();
/**
@@ -394,6 +404,7 @@ public abstract class AbstractDL implements AutoCloseable {
* @param normalizeDashes Whether to fold dashes to the ASCII hyphen.
* @return The optionally normalized text.
*/
+ @Internal(since = "3.0.0")
protected static String normalizeInput(final String text, final boolean normalizeWhitespace,
final boolean normalizeDashes) {
String result = text;
@@ -417,6 +428,7 @@ public abstract class AbstractDL implements AutoCloseable {
* @param normalizeDashes Whether to fold dashes to the ASCII hyphen.
* @return The optionally normalized text paired with its alignment back to {@code text}.
*/
+ @Internal(since = "3.0.0")
protected static AlignedText normalizeInputAligned(final String text,
final boolean normalizeWhitespace, final boolean normalizeDashes) {
// Compose each enabled fold's alignment with the running alignment so the returned mapping is
@@ -455,6 +467,7 @@ public abstract class AbstractDL implements AutoCloseable {
* @param splitOverlapSize The number of tokens shared between consecutive chunks.
* @return The chunk strings, in order.
*/
+ @Internal(since = "3.0.0")
protected static List<String> whitespaceChunks(final String text, final int documentSplitSize,
final int splitOverlapSize) {
final List<TextChunk> chunks = whitespaceChunkSpans(text, documentSplitSize, splitOverlapSize);
@@ -475,6 +488,7 @@ public abstract class AbstractDL implements AutoCloseable {
* @param splitOverlapSize The number of tokens shared between consecutive chunks.
* @return The chunks, in order, each with its character span in {@code text}.
*/
+ @Internal(since = "3.0.0")
protected static List<TextChunk> whitespaceChunkSpans(final String text,
final int documentSplitSize, final int splitOverlapSize) {
final List<Span> tokenSpans = WHITESPACE.splitSpans(text);
@@ -505,6 +519,7 @@ public abstract class AbstractDL implements AutoCloseable {
* @throws IllegalArgumentException Thrown if the token count is negative or the split settings
* cannot make progress.
*/
+ @Internal(since = "3.0.0")
protected static List<ChunkRange> chunkRanges(final int tokenCount, final int documentSplitSize,
final int splitOverlapSize) {
if (tokenCount < 0) {