diff --git a/src/main/java/org/opensearch/neuralsearch/processor/TextChunkingProcessor.java b/src/main/java/org/opensearch/neuralsearch/processor/TextChunkingProcessor.java index df8f4aebf..3a285dc50 100644 --- a/src/main/java/org/opensearch/neuralsearch/processor/TextChunkingProcessor.java +++ b/src/main/java/org/opensearch/neuralsearch/processor/TextChunkingProcessor.java @@ -301,7 +301,12 @@ private int chunkString(final String content, List result, final Map contentList, List result, final Map runTimeParameters, int chunkCount) { + private int chunkList( + final List contentList, + List result, + final Map runTimeParameters, + int chunkCount + ) { // flatten original output format from List> to List for (String content : contentList) { chunkCount = chunkString(content, result, runTimeParameters, chunkCount); diff --git a/src/main/java/org/opensearch/neuralsearch/processor/chunker/ChunkerFactory.java b/src/main/java/org/opensearch/neuralsearch/processor/chunker/ChunkerFactory.java index 6ee50442f..119c444d6 100644 --- a/src/main/java/org/opensearch/neuralsearch/processor/chunker/ChunkerFactory.java +++ b/src/main/java/org/opensearch/neuralsearch/processor/chunker/ChunkerFactory.java @@ -5,6 +5,7 @@ package org.opensearch.neuralsearch.processor.chunker; import com.google.common.collect.ImmutableMap; +import lombok.Getter; import java.util.Map; import java.util.Set; @@ -20,20 +21,24 @@ public class ChunkerFactory { FixedTokenLengthChunker.ALGORITHM_NAME, FixedTokenLengthChunker::new, DelimiterChunker.ALGORITHM_NAME, - FixedTokenLengthChunker::new + DelimiterChunker::new ); + @Getter + private static final Set allChunkers = chunkers.keySet(); + public static Chunker create(final String type, final Map parameters) { - Function, Chunker> chunkerConstructionFunction= chunkers.get(type); + Function, Chunker> chunkerConstructionFunction = chunkers.get(type); if (chunkerConstructionFunction == null) { throw new IllegalArgumentException( - String.format(Locale.ROOT, "chunking algorithm [%s] is not supported. Supported chunking algorithms are %s", type, chunkers.keySet()) + String.format( + Locale.ROOT, + "chunking algorithm [%s] is not supported. Supported chunking algorithms are %s", + type, + chunkers.keySet() + ) ); } return chunkerConstructionFunction.apply(parameters); } - - public static Set getAllChunkers() { - return chunkers.keySet(); - } } diff --git a/src/main/java/org/opensearch/neuralsearch/processor/chunker/ChunkerParameterValidator.java b/src/main/java/org/opensearch/neuralsearch/processor/chunker/ChunkerParameterValidator.java index 33c5fdee9..66fd072d1 100644 --- a/src/main/java/org/opensearch/neuralsearch/processor/chunker/ChunkerParameterValidator.java +++ b/src/main/java/org/opensearch/neuralsearch/processor/chunker/ChunkerParameterValidator.java @@ -59,7 +59,11 @@ public static Number validateNumberParameter(final Map parameter /** * Validate and parse the parameter for positive integer parameters */ - public static int validatePositiveIntegerParameter(final Map parameters, final String fieldName, final int defaultValue) { + public static int validatePositiveIntegerParameter( + final Map parameters, + final String fieldName, + final int defaultValue + ) { Number fieldValueNumber = validateNumberParameter(parameters, fieldName, defaultValue); int fieldValueInt = fieldValueNumber.intValue(); // sometimes parameter has negative default value, indicating that this parameter is not effective diff --git a/src/test/java/org/opensearch/neuralsearch/processor/chunker/ChunkerFactoryTests.java b/src/test/java/org/opensearch/neuralsearch/processor/chunker/ChunkerFactoryTests.java index 4bfb3f366..0d7f7d755 100644 --- a/src/test/java/org/opensearch/neuralsearch/processor/chunker/ChunkerFactoryTests.java +++ b/src/test/java/org/opensearch/neuralsearch/processor/chunker/ChunkerFactoryTests.java @@ -28,13 +28,13 @@ public void testGetAllChunkers() { public void testCreate_FixedTokenLength() { Chunker chunker = ChunkerFactory.create(FixedTokenLengthChunker.ALGORITHM_NAME, createChunkParameters()); assertNotNull(chunker); - assertTrue(chunker instanceof FixedTokenLengthChunker); + assert (chunker instanceof FixedTokenLengthChunker); } public void testCreate_Delimiter() { Chunker chunker = ChunkerFactory.create(DelimiterChunker.ALGORITHM_NAME, createChunkParameters()); assertNotNull(chunker); - assertTrue(chunker instanceof DelimiterChunker); + assert (chunker instanceof DelimiterChunker); } public void testCreate_Invalid() {