Code review comment: We are starting with printing out the size. The for loop, it loops all mined opinions.

Code before review:
public static void main(String[] args) {
TextAnalyticsClient client = new TextAnalyticsClientBuilder()
.credential(new AzureKeyCredential("{key}"))
.endpoint("{endpoint}")
.buildClient();
String document = "Bad atmosphere. Not close to plenty of restaurants, hotels, and transit! Staff are not friendly and helpful.";
System.out.printf("Text = %s%n", document);
AnalyzeSentimentOptions options = new AnalyzeSentimentOptions().setIncludeOpinionMining(true);
final DocumentSentiment documentSentiment = client.analyzeSentiment(document, "en", options);
SentimentConfidenceScores scores = documentSentiment.getConfidenceScores();
System.out.printf(
"Recognized document sentiment: %s, positive score: %f, neutral score: %f, negative score: %f.%n",
documentSentiment.getSentiment(), scores.getPositive(), scores.getNeutral(), scores.getNegative());
List<MinedOpinion> positiveMinedOpinions = new ArrayList<>();
List<MinedOpinion> mixedMinedOpinions = new ArrayList<>();
List<MinedOpinion> negativeMinedOpinions = new ArrayList<>();
documentSentiment.getSentences().forEach(sentenceSentiment -> {
SentimentConfidenceScores sentenceScores = sentenceSentiment.getConfidenceScores();
System.out.printf("\tSentence sentiment: %s, positive score: %f, neutral score: %f, negative score: %f.%n",
sentenceSentiment.getSentiment(), sentenceScores.getPositive(), sentenceScores.getNeutral(), sentenceScores.getNegative());
sentenceSentiment.getMinedOpinions().forEach(minedOpinion -> {
TextSentiment aspectTextSentiment = minedOpinion.getAspect().getSentiment();
if (NEGATIVE.equals(aspectTextSentiment)) {
negativeMinedOpinions.add(minedOpinion);
} else if (POSITIVE.equals(aspectTextSentiment)) {
positiveMinedOpinions.add(minedOpinion);
} else if (MIXED.equals(aspectTextSentiment)) {
mixedMinedOpinions.add(minedOpinion);
}
});
});
System.out.printf("Positive aspects count: %d%n", positiveMinedOpinions.size());
for (MinedOpinion positiveMinedOpinion : positiveMinedOpinions) {
System.out.printf("\tAspect: %s%n", positiveMinedOpinion.getAspect().getText());
for (OpinionSentiment opinionSentiment : positiveMinedOpinion.getOpinions()) {
System.out.printf("\t\t'%s' sentiment because of \"%s\". Is the aspect negated: %s.%n",
opinionSentiment.getSentiment(), opinionSentiment.getText(), opinionSentiment.isNegated());
}
}
System.out.printf("Mixed aspects count: %d%n", mixedMinedOpinions.size());
for (MinedOpinion mixedMinedOpinion : mixedMinedOpinions) {
System.out.printf("\tAspect: %s%n", mixedMinedOpinion.getAspect().getText());
for (OpinionSentiment opinionSentiment : mixedMinedOpinion.getOpinions()) {
System.out.printf("\t\t'%s' sentiment because of \"%s\". Is the aspect negated: %s.%n",
opinionSentiment.getSentiment(), opinionSentiment.getText(), opinionSentiment.isNegated());
}
}
System.out.printf("Negative aspects count: %d%n", negativeMinedOpinions.size());
for (MinedOpinion negativeMinedOpinion : negativeMinedOpinions) {
System.out.printf("\tAspect: %s%n", negativeMinedOpinion.getAspect().getText());
for (OpinionSentiment opinionSentiment : negativeMinedOpinion.getOpinions()) {
System.out.printf("\t\t'%s' sentiment because of \"%s\". Is the aspect negated: %s.%n",
opinionSentiment.getSentiment(), opinionSentiment.getText(), opinionSentiment.isNegated());
}
}
}

Line under review: System.out.printf("Positive aspects count: %d%n", positiveMinedOpinions.size());

Code after addressing the review:
public static void main(String[] args) {
TextAnalyticsClient client = new TextAnalyticsClientBuilder()
.credential(new AzureKeyCredential("{key}"))
.endpoint("{endpoint}")
.buildClient();
String document = "Bad atmosphere. Not close to plenty of restaurants, hotels, and transit! Staff are not friendly and helpful.";
System.out.printf("Text = %s%n", document);
AnalyzeSentimentOptions options = new AnalyzeSentimentOptions().setIncludeOpinionMining(true);
final DocumentSentiment documentSentiment = client.analyzeSentiment(document, "en", options);
SentimentConfidenceScores scores = documentSentiment.getConfidenceScores();
System.out.printf(
"Recognized document sentiment: %s, positive score: %f, neutral score: %f, negative score: %f.%n",
documentSentiment.getSentiment(), scores.getPositive(), scores.getNeutral(), scores.getNegative());
documentSentiment.getSentences().forEach(sentenceSentiment -> {
SentimentConfidenceScores sentenceScores = sentenceSentiment.getConfidenceScores();
System.out.printf("\tSentence sentiment: %s, positive score: %f, neutral score: %f, negative score: %f.%n",
sentenceSentiment.getSentiment(), sentenceScores.getPositive(), sentenceScores.getNeutral(), sentenceScores.getNegative());
sentenceSentiment.getMinedOpinions().forEach(minedOpinions -> {
AspectSentiment aspectSentiment = minedOpinions.getAspect();
System.out.printf("\t\tAspect sentiment: %s, aspect text: %s%n", aspectSentiment.getSentiment(),
aspectSentiment.getText());
for (OpinionSentiment opinionSentiment : minedOpinions.getOpinions()) {
System.out.printf("\t\t\t'%s' opinion sentiment because of \"%s\". Is the opinion negated: %s.%n",
opinionSentiment.getSentiment(), opinionSentiment.getText(), opinionSentiment.isNegated());
}
});
});
}