Skip to content

Commit

Permalink
Update tests models and feedback (Azure#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
samvaity authored Dec 19, 2019
1 parent 0773081 commit aef907e
Show file tree
Hide file tree
Showing 13 changed files with 363 additions and 316 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.azure.ai.textanalytics.models.RecognizeEntitiesResult;
import com.azure.ai.textanalytics.models.TextAnalyticsRequestOptions;
import com.azure.ai.textanalytics.models.TextDocumentInput;
import com.azure.ai.textanalytics.models.TextSentimentResult;
import com.azure.ai.textanalytics.models.AnalyzeSentimentResult;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
Expand Down Expand Up @@ -570,12 +570,12 @@ public Response<DocumentResultCollection<ExtractKeyPhraseResult>> extractBatchKe
* (Positive, Negative, and Neutral) for the document and each sentence within i
*
* @param text the text to be analyzed.
* @return the {@link TextSentimentResult text sentiments} of the text.
* @return the {@link AnalyzeSentimentResult text sentiments} of the text.
*
* @throws NullPointerException if {@code text} is {@code null}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public TextSentimentResult analyzeSentiment(String text) {
public AnalyzeSentimentResult analyzeSentiment(String text) {
return analyzeBatchSentimentWithResponse(text, defaultLanguage, Context.NONE).getValue();
}

Expand All @@ -588,11 +588,11 @@ public TextSentimentResult analyzeSentiment(String text) {
* English as default.
* @param context Additional context that is passed through the Http pipeline during the service call.
*
* @return A {@link Response} containing the {@link TextSentimentResult text sentiments} of the text.
* @return A {@link Response} containing the {@link AnalyzeSentimentResult text sentiments} of the text.
* @throws NullPointerException if {@code text} is {@code null}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<TextSentimentResult> analyzeBatchSentimentWithResponse(
public Response<AnalyzeSentimentResult> analyzeBatchSentimentWithResponse(
String text, String language, Context context) {
return client.analyzeSentimentWithResponse(text, language, context).block();
}
Expand All @@ -604,11 +604,11 @@ public Response<TextSentimentResult> analyzeBatchSentimentWithResponse(
* @param textInputs A list of text to be analyzed.
*
* @return A {@link DocumentResultCollection batch} containing the list of
* {@link TextSentimentResult text sentiments} with their numeric scores.
* {@link AnalyzeSentimentResult text sentiments} with their numeric scores.
* @throws NullPointerException if {@code textInputs} is {@code null}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public DocumentResultCollection<TextSentimentResult> analyzeSentiment(List<String> textInputs) {
public DocumentResultCollection<AnalyzeSentimentResult> analyzeSentiment(List<String> textInputs) {
return analyzeSentimentWithResponse(textInputs, defaultLanguage, Context.NONE).getValue();
}

Expand All @@ -622,11 +622,11 @@ public DocumentResultCollection<TextSentimentResult> analyzeSentiment(List<Strin
* @param context Additional context that is passed through the Http pipeline during the service call.
*
* @return A {@link Response} containing the {@link DocumentResultCollection batch} of
* {@link TextSentimentResult text sentiments} with their numeric scores.
* {@link AnalyzeSentimentResult text sentiments} with their numeric scores.
* @throws NullPointerException if {@code textInputs} is {@code null}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<DocumentResultCollection<TextSentimentResult>> analyzeSentimentWithResponse(
public Response<DocumentResultCollection<AnalyzeSentimentResult>> analyzeSentimentWithResponse(
List<String> textInputs, String language, Context context) {
return client.analyzeSentimentWithResponse(textInputs, language, context).block();
}
Expand All @@ -637,11 +637,11 @@ public Response<DocumentResultCollection<TextSentimentResult>> analyzeSentimentW
*
* @param textInputs A list of {@link TextDocumentInput inputs/documents} to be analyzed.
*
* @return A {@link DocumentResultCollection batch} of {@link TextSentimentResult text sentiments}.
* @return A {@link DocumentResultCollection batch} of {@link AnalyzeSentimentResult text sentiments}.
* @throws NullPointerException if {@code textInputs} is {@code null}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public DocumentResultCollection<TextSentimentResult> analyzeBatchSentiment(List<TextDocumentInput> textInputs) {
public DocumentResultCollection<AnalyzeSentimentResult> analyzeBatchSentiment(List<TextDocumentInput> textInputs) {
return analyzeBatchSentimentWithResponse(textInputs, null, Context.NONE).getValue();
}

Expand All @@ -655,11 +655,11 @@ public DocumentResultCollection<TextSentimentResult> analyzeBatchSentiment(List<
* @param context Additional context that is passed through the Http pipeline during the service call.
*
* @return A {@link Response} containing the {@link DocumentResultCollection batch} of
* {@link TextSentimentResult text sentiments}.
* {@link AnalyzeSentimentResult text sentiments}.
* @throws NullPointerException if {@code textInputs} is {@code null}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<DocumentResultCollection<TextSentimentResult>> analyzeBatchSentimentWithResponse(
public Response<DocumentResultCollection<AnalyzeSentimentResult>> analyzeBatchSentimentWithResponse(
List<TextDocumentInput> textInputs, TextAnalyticsRequestOptions options, Context context) {
return client.analyzeBatchSentimentWithResponse(textInputs, options, context).block();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.azure.ai.textanalytics.implementation.models.LanguageResult;
import com.azure.ai.textanalytics.implementation.models.MultiLanguageBatchInput;
import com.azure.ai.textanalytics.implementation.models.SentimentResponse;
import com.azure.ai.textanalytics.implementation.models.TextAnalyticsErrorException;
import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Host;
Expand All @@ -22,6 +21,7 @@
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.HttpPipelineBuilder;
import com.azure.core.http.policy.CookiePolicy;
Expand Down Expand Up @@ -105,32 +105,32 @@ public TextAnalyticsClientImpl(HttpPipeline httpPipeline) {
private interface TextAnalyticsClientService {
@Post("entities/recognition/general")
@ExpectedResponses({200})
@UnexpectedResponseExceptionType(TextAnalyticsErrorException.class)
@UnexpectedResponseExceptionType(HttpResponseException.class)
Mono<SimpleResponse<EntitiesResult>> entitiesRecognitionGeneral(@HostParam("Endpoint") String endpoint, @QueryParam("model-version") String modelVersion, @QueryParam("showStats") Boolean showStats, @BodyParam("application/json; charset=utf-8") MultiLanguageBatchInput input, Context context);

@Post("entities/recognition/pii")
@ExpectedResponses({200})
@UnexpectedResponseExceptionType(TextAnalyticsErrorException.class)
@UnexpectedResponseExceptionType(HttpResponseException.class)
Mono<SimpleResponse<EntitiesResult>> entitiesRecognitionPii(@HostParam("Endpoint") String endpoint, @QueryParam("model-version") String modelVersion, @QueryParam("showStats") Boolean showStats, @BodyParam("application/json; charset=utf-8") MultiLanguageBatchInput input, Context context);

@Post("entities/linking")
@ExpectedResponses({200})
@UnexpectedResponseExceptionType(TextAnalyticsErrorException.class)
@UnexpectedResponseExceptionType(HttpResponseException.class)
Mono<SimpleResponse<EntityLinkingResult>> entitiesLinking(@HostParam("Endpoint") String endpoint, @QueryParam("model-version") String modelVersion, @QueryParam("showStats") Boolean showStats, @BodyParam("application/json; charset=utf-8") MultiLanguageBatchInput input, Context context);

@Post("keyPhrases")
@ExpectedResponses({200})
@UnexpectedResponseExceptionType(TextAnalyticsErrorException.class)
@UnexpectedResponseExceptionType(HttpResponseException.class)
Mono<SimpleResponse<KeyPhraseResult>> keyPhrases(@HostParam("Endpoint") String endpoint, @QueryParam("model-version") String modelVersion, @QueryParam("showStats") Boolean showStats, @BodyParam("application/json; charset=utf-8") MultiLanguageBatchInput input, Context context);

@Post("languages")
@ExpectedResponses({200})
@UnexpectedResponseExceptionType(TextAnalyticsErrorException.class)
@UnexpectedResponseExceptionType(HttpResponseException.class)
Mono<SimpleResponse<LanguageResult>> languages(@HostParam("Endpoint") String endpoint, @QueryParam("model-version") String modelVersion, @QueryParam("showStats") Boolean showStats, @BodyParam("application/json; charset=utf-8") LanguageBatchInput input, Context context);

@Post("sentiment")
@ExpectedResponses({200})
@UnexpectedResponseExceptionType(TextAnalyticsErrorException.class)
@UnexpectedResponseExceptionType(HttpResponseException.class)
Mono<SimpleResponse<SentimentResponse>> sentiment(@HostParam("Endpoint") String endpoint, @QueryParam("model-version") String modelVersion, @QueryParam("showStats") Boolean showStats, @BodyParam("application/json; charset=utf-8") MultiLanguageBatchInput input, Context context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import java.util.List;

/**
* The TextSentimentResult model.
* The AnalyzeSentimentResult model.
*/
@Immutable
public final class TextSentimentResult extends DocumentResult {
public final class AnalyzeSentimentResult extends DocumentResult {
private final TextSentiment documentSentiment;
private final List<TextSentiment> sentenceSentiments;

Expand All @@ -24,7 +24,7 @@ public final class TextSentimentResult extends DocumentResult {
* @param documentSentiment the document sentiment
* @param sentenceSentiments a list of sentence sentiments
*/
public TextSentimentResult(String id, TextDocumentStatistics textDocumentStatistics, TextAnalyticsError error,
public AnalyzeSentimentResult(String id, TextDocumentStatistics textDocumentStatistics, TextAnalyticsError error,
TextSentiment documentSentiment, List<TextSentiment> sentenceSentiments) {
super(id, textDocumentStatistics, error);
this.documentSentiment = documentSentiment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class DocumentResult {
* @param textDocumentStatistics text document statistics
* @param error the document error.
*/
DocumentResult(final String id, final TextDocumentStatistics textDocumentStatistics, final TextAnalyticsError error) {
DocumentResult(final String id, final TextDocumentStatistics textDocumentStatistics, TextAnalyticsError error) {
this.id = id;
this.error = error;
this.isError = error != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,15 @@ public final class TextAnalyticsError {
*/
private final String target;

/*
* Inner error contains more specific information.
*/
private final InnerError innerError;

/*
* Details about specific errors that led to this reported error.
*/
private final List<TextAnalyticsError> details;

public TextAnalyticsError(ErrorCodeValue code, String message, String target, InnerError innerError,
List<TextAnalyticsError> details) {
public TextAnalyticsError(ErrorCodeValue code, String message, String target, List<TextAnalyticsError> details) {
this.code = code;
this.message = message;
this.target = target;
this.innerError = innerError;
this.details = details;
}

Expand Down Expand Up @@ -77,17 +70,6 @@ public String getTarget() {
return this.target;
}

// TODO: spotbugs errors. infinite call
// /**
// * Get the innerError property: Inner error contains more specific
// * information.
// *
// * @return the innerError value.
// */
// public InnerError getInnerError() {
// return this.innerError;
// }

/**
* Get the details property: Details about specific errors that led to this
* reported error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.azure.core.annotation.Immutable;

/**
* if showStats=true was specified in the request this field will contain
* If {@link TextAnalyticsRequestOptions#showStatistics()} is set to {@code true} this class will will contain
* information about the request payload.
*/
@Immutable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.azure.core.annotation.Immutable;

/**
* if showStats=true was specified in the request this field will contain
* If {@link TextAnalyticsRequestOptions#showStatistics()} is set to {@code true} this class will will contain
* information about the document payload.
*/
@Immutable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package com.azure.ai.textanalytics;

import com.azure.ai.textanalytics.models.TextSentiment;
import com.azure.ai.textanalytics.models.TextSentimentResult;
import com.azure.ai.textanalytics.models.AnalyzeSentimentResult;

import java.util.List;

Expand All @@ -27,7 +27,7 @@ public static void main(String[] args) {
// The text that need be analysed.
String text = "The hotel was dark and unclean.";

final TextSentimentResult sentimentResult = client.analyzeSentiment(text);
final AnalyzeSentimentResult sentimentResult = client.analyzeSentiment(text);

final TextSentiment documentSentiment = sentimentResult.getDocumentSentiment();
System.out.printf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.azure.ai.textanalytics.models.TextDocumentBatchStatistics;
import com.azure.ai.textanalytics.models.TextDocumentInput;
import com.azure.ai.textanalytics.models.TextSentiment;
import com.azure.ai.textanalytics.models.TextSentimentResult;
import com.azure.ai.textanalytics.models.AnalyzeSentimentResult;
import com.azure.core.util.Context;

import java.util.Arrays;
Expand Down Expand Up @@ -39,7 +39,7 @@ public static void main(String[] args) {
);

final TextAnalyticsRequestOptions requestOptions = new TextAnalyticsRequestOptions().setShowStatistics(true);
DocumentResultCollection<TextSentimentResult> detectedBatchResult = client.analyzeBatchSentimentWithResponse(inputs, requestOptions, Context.NONE).getValue();
DocumentResultCollection<AnalyzeSentimentResult> detectedBatchResult = client.analyzeBatchSentimentWithResponse(inputs, requestOptions, Context.NONE).getValue();
System.out.printf("Model version: %s%n", detectedBatchResult.getModelVersion());

final TextDocumentBatchStatistics batchStatistics = detectedBatchResult.getStatistics();
Expand All @@ -50,16 +50,16 @@ public static void main(String[] args) {
batchStatistics.getValidDocumentCount());

// Detecting sentiment for each of document from a batch of documents
for (TextSentimentResult textSentimentResult : detectedBatchResult) {
final TextSentiment documentSentiment = textSentimentResult.getDocumentSentiment();
for (AnalyzeSentimentResult analyzeSentimentResult : detectedBatchResult) {
final TextSentiment documentSentiment = analyzeSentimentResult.getDocumentSentiment();
System.out.printf("Recognized document sentiment: %s, Positive Score: %s, Neutral Score: %s, Negative Score: %s. Length of sentence: %s, Offset of sentence: %s.%n",
documentSentiment.getTextSentimentClass(),
documentSentiment.getPositiveScore(),
documentSentiment.getNeutralScore(),
documentSentiment.getNegativeScore(),
documentSentiment.getLength(),
documentSentiment.getOffset());
for (TextSentiment sentenceSentiment : textSentimentResult.getSentenceSentiments()) {
for (TextSentiment sentenceSentiment : analyzeSentimentResult.getSentenceSentiments()) {
System.out.printf("Recognized sentence sentiment: %s, Positive Score: %s, Neutral Score: %s, Negative Score: %s. Length of sentence: %s, Offset of sentence: %s.%n",
sentenceSentiment.getTextSentimentClass(),
sentenceSentiment.getPositiveScore(),
Expand Down
Loading

0 comments on commit aef907e

Please sign in to comment.