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

add default delimiter value #8

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
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public void validateParameters(Map<String, Object> parameters) {
} else if (((String) delimiter).isEmpty()) {
throw new IllegalArgumentException("delimiter parameters should not be empty.");
}
} else {
throw new IllegalArgumentException("You must contain field: " + DELIMITER_FIELD + " in your parameter.");
}
if (parameters.containsKey(MAX_CHUNK_LIMIT_FIELD)) {
Object maxChunkLimit = parameters.get(MAX_CHUNK_LIMIT_FIELD);
Expand All @@ -40,7 +38,7 @@ public void validateParameters(Map<String, Object> parameters) {

@Override
public List<String> chunk(String content, Map<String, Object> parameters) {
String delimiter = (String) parameters.get(DELIMITER_FIELD);
String delimiter = (String) parameters.getOrDefault(DELIMITER_FIELD, ".");
int maxChunkingNumber = (int) parameters.getOrDefault(MAX_CHUNK_LIMIT_FIELD, -1);
List<String> chunkResult = new ArrayList<>();
int start = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@

public class DelimiterChunkerTests extends OpenSearchTestCase {

public void testChunkerWithNoDelimiterField() {
DelimiterChunker chunker = new DelimiterChunker();
String content = "a\nb\nc\nd";
Map<String, Object> inputParameters = Map.of("", "");
Exception exception = assertThrows(IllegalArgumentException.class, () -> chunker.validateParameters(inputParameters));
Assert.assertEquals("You must contain field: " + DELIMITER_FIELD + " in your parameter.", exception.getMessage());
}

public void testChunkerWithWrongLimitFieldList() {
DelimiterChunker chunker = new DelimiterChunker();
String content = "a\nb\nc\nd";
Expand Down Expand Up @@ -81,6 +73,14 @@ public void testChunker() {
assertEquals(List.of("a\n", "b\n", "c\n", "d"), chunkResult);
}

public void testChunkerWithDefaultDelimiter() {
DelimiterChunker chunker = new DelimiterChunker();
String content = "a.b.c.d";
Map<String, Object> inputParameters = Map.of();
List<String> chunkResult = chunker.chunk(content, inputParameters);
assertEquals(List.of("a.", "b.", "c.", "d"), chunkResult);
}

public void testChunkerWithDelimiterEnd() {
DelimiterChunker chunker = new DelimiterChunker();
String content = "a\nb\nc\nd\n";
Expand Down
Loading