Skip to content

Commit

Permalink
tune code
Browse files Browse the repository at this point in the history
Signed-off-by: yuye-aws <[email protected]>
  • Loading branch information
yuye-aws committed Mar 15, 2024
1 parent 2ce9840 commit 2aea7a5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import com.google.common.annotations.VisibleForTesting;

Expand Down Expand Up @@ -116,14 +115,13 @@ private void parseAlgorithmMap(final Map<String, Object> algorithmMap) {
}
}

Set<String> allChunkerAlgorithms = ChunkerFactory.allChunkerAlgorithms;
if (!allChunkerAlgorithms.contains(algorithmKey)) {
if (!ChunkerFactory.CHUNKER_ALGORITHMS.contains(algorithmKey)) {
throw new IllegalArgumentException(
String.format(
Locale.ROOT,
"Chunking algorithm [%s] is not supported. Supported chunking algorithms are %s",
algorithmKey,
allChunkerAlgorithms
ChunkerFactory.CHUNKER_ALGORITHMS
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package org.opensearch.neuralsearch.processor.chunker;

import com.google.common.collect.ImmutableMap;
import lombok.Getter;

import java.util.Map;
import java.util.Objects;
Expand All @@ -19,18 +18,17 @@ public final class ChunkerFactory {

private ChunkerFactory() {} // no instance of this factory class

private static final Map<String, Function<Map<String, Object>, Chunker>> chunkerConstructors = ImmutableMap.of(
private static final Map<String, Function<Map<String, Object>, Chunker>> CHUNKERS_CONSTRUCTORS = ImmutableMap.of(
FixedTokenLengthChunker.ALGORITHM_NAME,
FixedTokenLengthChunker::new,
DelimiterChunker.ALGORITHM_NAME,
DelimiterChunker::new
);

@Getter
public static Set<String> allChunkerAlgorithms = chunkerConstructors.keySet();
public static Set<String> CHUNKER_ALGORITHMS = CHUNKERS_CONSTRUCTORS.keySet();

public static Chunker create(final String type, final Map<String, Object> parameters) {
Function<Map<String, Object>, Chunker> chunkerConstructionFunction = chunkerConstructors.get(type);
Function<Map<String, Object>, Chunker> chunkerConstructionFunction = CHUNKERS_CONSTRUCTORS.get(type);
// chunkerConstructionFunction is not null because we have validated the type in text chunking processor
Objects.requireNonNull(chunkerConstructionFunction);
return chunkerConstructionFunction.apply(parameters);
Expand Down

0 comments on commit 2aea7a5

Please sign in to comment.