Skip to content

Commit

Permalink
support map type as an input
Browse files Browse the repository at this point in the history
Signed-off-by: yuye-aws <[email protected]>
  • Loading branch information
yuye-aws committed Feb 26, 2024
1 parent 06933d2 commit 617104f
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,21 @@ public IngestDocument execute(IngestDocument document) {
);
}
}
} else if (content instanceof Map<?, ?>) {
Map<?, ?> contentMap = (Map<?, ?>) content;
for (Object contentElement : contentMap.values()) {
if (!(contentElement instanceof String)) {
throw new IllegalArgumentException(
"some element in input field map ["
+ inputField
+ "] of type ["
+ contentElement.getClass().getName()
+ "] cannot be cast to ["
+ String.class.getName()
+ "]"
);
}
}
} else if (!(content instanceof String)) {
throw new IllegalArgumentException(
"input field ["
Expand Down Expand Up @@ -190,10 +205,15 @@ public IngestDocument execute(IngestDocument document) {
IFieldChunker chunker = ChunkerFactory.create(parameterKey, analysisRegistry);
if (content instanceof String) {
chunkedPassages = chunker.chunk((String) content, chunkerParameters);
} else {
} else if (content instanceof List<?>) {
for (Object contentElement : (List<?>) content) {
chunkedPassages.addAll(chunker.chunk((String) contentElement, chunkerParameters));
}
} else {
// content is map type
for (Object contentElement : ((Map<?, ?>) content).values()) {
chunkedPassages.addAll(chunker.chunk((String) contentElement, chunkerParameters));
}
}
}
}
Expand Down

0 comments on commit 617104f

Please sign in to comment.