Source:
private AnalyzeSentimentResult convertToTextSentimentResult(final DocumentSentiment documentSentiment) { final TextSentimentClass documentSentimentClass = TextSentimentClass.fromString(documentSentiment. getSentiment().toString()); if (documentSentimentClass == null) { throw logger.logExceptionAsWarning( new RuntimeException(String.format("'%s' is not valid text sentiment.", documentSentiment.getSentiment()))); } final SentimentConfidenceScorePerLabel confidenceScorePerLabel = documentSentiment.getDocumentScores(); final List<TextSentiment> sentenceSentimentTexts = documentSentiment.getSentences().stream() .map(sentenceSentiment -> { TextSentimentClass sentimentClass = TextSentimentClass.fromString(sentenceSentiment .getSentiment().toString()); if (sentimentClass == null) { throw logger.logExceptionAsWarning( new RuntimeException(String.format("'%s' is not valid text sentiment.", sentenceSentiment.getSentiment()))); } SentimentConfidenceScorePerLabel confidenceScorePerSentence = sentenceSentiment.getSentenceScores(); return new TextSentiment(sentimentClass, confidenceScorePerSentence.getNegative(), confidenceScorePerSentence.getNeutral(), confidenceScorePerSentence.getPositive(), sentenceSentiment.getLength(), sentenceSentiment.getOffset()); }).collect(Collectors.toList()); return new AnalyzeSentimentResult(documentSentiment.getId(), documentSentiment.getStatistics() == null ? null : convertToTextDocumentStatistics(documentSentiment.getStatistics()), null, new TextSentiment(documentSentimentClass, confidenceScorePerLabel.getNegative(), confidenceScorePerLabel.getNeutral(), confidenceScorePerLabel.getPositive(), sentenceSentimentTexts.stream().mapToInt(TextSentiment::getLength).sum(), 0), sentenceSentimentTexts); }

Target:
private AnalyzeSentimentResult convertToTextSentimentResult(final DocumentSentiment documentSentiment) { final TextSentimentClass documentSentimentClass = TextSentimentClass.fromString(documentSentiment. getSentiment().toString()); if (documentSentimentClass == null) { logger.logExceptionAsWarning( new RuntimeException(String.format("'%s' is not valid text sentiment.", documentSentiment.getSentiment()))); } final SentimentConfidenceScorePerLabel confidenceScorePerLabel = documentSentiment.getDocumentScores(); final List<TextSentiment> sentenceSentimentTexts = documentSentiment.getSentences().stream() .map(sentenceSentiment -> { TextSentimentClass sentimentClass = TextSentimentClass.fromString(sentenceSentiment .getSentiment().toString()); if (sentimentClass == null) { logger.logExceptionAsWarning( new RuntimeException(String.format("'%s' is not valid text sentiment.", sentenceSentiment.getSentiment()))); } SentimentConfidenceScorePerLabel confidenceScorePerSentence = sentenceSentiment.getSentenceScores(); return new TextSentiment(sentimentClass, confidenceScorePerSentence.getNegative(), confidenceScorePerSentence.getNeutral(), confidenceScorePerSentence.getPositive(), sentenceSentiment.getLength(), sentenceSentiment.getOffset()); }).collect(Collectors.toList()); return new AnalyzeSentimentResult(documentSentiment.getId(), documentSentiment.getStatistics() == null ? null : convertToTextDocumentStatistics(documentSentiment.getStatistics()), null, new TextSentiment(documentSentimentClass, confidenceScorePerLabel.getNegative(), confidenceScorePerLabel.getNeutral(), confidenceScorePerLabel.getPositive(), sentenceSentimentTexts.stream().mapToInt(TextSentiment::getLength).sum(), 0), sentenceSentimentTexts); }