@Test public void successBatchDetectKeyPhrasesCall() { when(mockComprehendClient.batchDetectKeyPhrases(any(BatchDetectKeyPhrasesRequest.class))) .thenReturn(mockBatchDetectKeyPhrasesResult); BatchResponse result = test.sendBatchRequest( TestConstants.FIELD_LOCATOR_LIST, TestConstants.CONTENT_LIST, TestConstants.LANGUAGE_CODE, mockComprehendClient); assertEquals(TestConstants.FIELD_LOCATOR_LIST, result.getLocatorList()); }
@Override public BatchResponse sendBatchRequest(@NonNull final List<BatchFieldLocator> fieldLocatorList, @NonNull final List<String> contentList, @NonNull final LanguageCode languageCode, @NonNull final AmazonComprehend comprehendClient) { BatchDetectKeyPhrasesRequest request = new BatchDetectKeyPhrasesRequest().withTextList(contentList).withLanguageCode(languageCode.toString()); BatchDetectKeyPhrasesResult batchDetectKeyPhrasesResult = comprehendClient.batchDetectKeyPhrases(request); List<JSONObject> copiedKeyPhrasesList = new ArrayList<>(); for (BatchDetectKeyPhrasesItemResult resultItem : batchDetectKeyPhrasesResult.getResultList()) { List<JSONObject> keyPhraseJsonList = resultItem.getKeyPhrases() .stream().map(JSONObject::new).collect(Collectors.toList()); try { copiedKeyPhrasesList.add(new JSONObject().put(Constants.KEYPHRASES_KEY_NAME, keyPhraseJsonList)); } catch (JSONException e) { copiedKeyPhrasesList.add(null); } } return new BatchResponse<>( fieldLocatorList, batchDetectKeyPhrasesResult.getResultList(), batchDetectKeyPhrasesResult.getErrorList(), copiedKeyPhrasesList); }
DetectKeyPhrases implements ComprehendOperation { @Override public BatchResponse sendBatchRequest(@NonNull final List<BatchFieldLocator> fieldLocatorList, @NonNull final List<String> contentList, @NonNull final LanguageCode languageCode, @NonNull final AmazonComprehend comprehendClient) { BatchDetectKeyPhrasesRequest request = new BatchDetectKeyPhrasesRequest().withTextList(contentList).withLanguageCode(languageCode.toString()); BatchDetectKeyPhrasesResult batchDetectKeyPhrasesResult = comprehendClient.batchDetectKeyPhrases(request); List<JSONObject> copiedKeyPhrasesList = new ArrayList<>(); for (BatchDetectKeyPhrasesItemResult resultItem : batchDetectKeyPhrasesResult.getResultList()) { List<JSONObject> keyPhraseJsonList = resultItem.getKeyPhrases() .stream().map(JSONObject::new).collect(Collectors.toList()); try { copiedKeyPhrasesList.add(new JSONObject().put(Constants.KEYPHRASES_KEY_NAME, keyPhraseJsonList)); } catch (JSONException e) { copiedKeyPhrasesList.add(null); } } return new BatchResponse<>( fieldLocatorList, batchDetectKeyPhrasesResult.getResultList(), batchDetectKeyPhrasesResult.getErrorList(), copiedKeyPhrasesList); } }
DetectKeyPhrases implements ComprehendOperation { @Override public BatchResponse sendBatchRequest(@NonNull final List<BatchFieldLocator> fieldLocatorList, @NonNull final List<String> contentList, @NonNull final LanguageCode languageCode, @NonNull final AmazonComprehend comprehendClient) { BatchDetectKeyPhrasesRequest request = new BatchDetectKeyPhrasesRequest().withTextList(contentList).withLanguageCode(languageCode.toString()); BatchDetectKeyPhrasesResult batchDetectKeyPhrasesResult = comprehendClient.batchDetectKeyPhrases(request); List<JSONObject> copiedKeyPhrasesList = new ArrayList<>(); for (BatchDetectKeyPhrasesItemResult resultItem : batchDetectKeyPhrasesResult.getResultList()) { List<JSONObject> keyPhraseJsonList = resultItem.getKeyPhrases() .stream().map(JSONObject::new).collect(Collectors.toList()); try { copiedKeyPhrasesList.add(new JSONObject().put(Constants.KEYPHRASES_KEY_NAME, keyPhraseJsonList)); } catch (JSONException e) { copiedKeyPhrasesList.add(null); } } return new BatchResponse<>( fieldLocatorList, batchDetectKeyPhrasesResult.getResultList(), batchDetectKeyPhrasesResult.getErrorList(), copiedKeyPhrasesList); }  }
DetectKeyPhrases implements ComprehendOperation { @Override public BatchResponse sendBatchRequest(@NonNull final List<BatchFieldLocator> fieldLocatorList, @NonNull final List<String> contentList, @NonNull final LanguageCode languageCode, @NonNull final AmazonComprehend comprehendClient) { BatchDetectKeyPhrasesRequest request = new BatchDetectKeyPhrasesRequest().withTextList(contentList).withLanguageCode(languageCode.toString()); BatchDetectKeyPhrasesResult batchDetectKeyPhrasesResult = comprehendClient.batchDetectKeyPhrases(request); List<JSONObject> copiedKeyPhrasesList = new ArrayList<>(); for (BatchDetectKeyPhrasesItemResult resultItem : batchDetectKeyPhrasesResult.getResultList()) { List<JSONObject> keyPhraseJsonList = resultItem.getKeyPhrases() .stream().map(JSONObject::new).collect(Collectors.toList()); try { copiedKeyPhrasesList.add(new JSONObject().put(Constants.KEYPHRASES_KEY_NAME, keyPhraseJsonList)); } catch (JSONException e) { copiedKeyPhrasesList.add(null); } } return new BatchResponse<>( fieldLocatorList, batchDetectKeyPhrasesResult.getResultList(), batchDetectKeyPhrasesResult.getErrorList(), copiedKeyPhrasesList); }  @Override String[] getVisualizationNameList(); @Override SingularResponse sendSingularRequest(@NonNull final String fieldNameAndOperation,
                                                @NonNull final String content,
                                                @NonNull final LanguageCode languageCode,
                                                @NonNull final AmazonComprehend comprehendClient); @Override BatchResponse sendBatchRequest(@NonNull final List<BatchFieldLocator> fieldLocatorList,
                                          @NonNull final List<String> contentList,
                                          @NonNull final LanguageCode languageCode,
                                          @NonNull final AmazonComprehend comprehendClient); }
DetectKeyPhrases implements ComprehendOperation { @Override public BatchResponse sendBatchRequest(@NonNull final List<BatchFieldLocator> fieldLocatorList, @NonNull final List<String> contentList, @NonNull final LanguageCode languageCode, @NonNull final AmazonComprehend comprehendClient) { BatchDetectKeyPhrasesRequest request = new BatchDetectKeyPhrasesRequest().withTextList(contentList).withLanguageCode(languageCode.toString()); BatchDetectKeyPhrasesResult batchDetectKeyPhrasesResult = comprehendClient.batchDetectKeyPhrases(request); List<JSONObject> copiedKeyPhrasesList = new ArrayList<>(); for (BatchDetectKeyPhrasesItemResult resultItem : batchDetectKeyPhrasesResult.getResultList()) { List<JSONObject> keyPhraseJsonList = resultItem.getKeyPhrases() .stream().map(JSONObject::new).collect(Collectors.toList()); try { copiedKeyPhrasesList.add(new JSONObject().put(Constants.KEYPHRASES_KEY_NAME, keyPhraseJsonList)); } catch (JSONException e) { copiedKeyPhrasesList.add(null); } } return new BatchResponse<>( fieldLocatorList, batchDetectKeyPhrasesResult.getResultList(), batchDetectKeyPhrasesResult.getErrorList(), copiedKeyPhrasesList); }  @Override String[] getVisualizationNameList(); @Override SingularResponse sendSingularRequest(@NonNull final String fieldNameAndOperation,
                                                @NonNull final String content,
                                                @NonNull final LanguageCode languageCode,
                                                @NonNull final AmazonComprehend comprehendClient); @Override BatchResponse sendBatchRequest(@NonNull final List<BatchFieldLocator> fieldLocatorList,
                                          @NonNull final List<String> contentList,
                                          @NonNull final LanguageCode languageCode,
                                          @NonNull final AmazonComprehend comprehendClient);  }