diff --git a/google-cloud-clients/google-cloud-language/src/main/java/com/google/cloud/language/v1/LanguageServiceClient.java b/google-cloud-clients/google-cloud-language/src/main/java/com/google/cloud/language/v1/LanguageServiceClient.java index df590debd8a9..d2db5d05e07c 100644 --- a/google-cloud-clients/google-cloud-language/src/main/java/com/google/cloud/language/v1/LanguageServiceClient.java +++ b/google-cloud-clients/google-cloud-language/src/main/java/com/google/cloud/language/v1/LanguageServiceClient.java @@ -36,7 +36,8 @@ * * try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) { * Document document = Document.newBuilder().build(); - * AnalyzeSentimentResponse response = languageServiceClient.analyzeSentiment(document); + * EncodingType encodingType = EncodingType.NONE; + * AnalyzeSentimentResponse response = languageServiceClient.analyzeSentiment(document, encodingType); * } * * @@ -146,6 +147,35 @@ public LanguageServiceStub getStub() { return stub; } + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Analyzes the sentiment of the provided text. + * + *

Sample code: + * + *


+   * try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
+   *   Document document = Document.newBuilder().build();
+   *   EncodingType encodingType = EncodingType.NONE;
+   *   AnalyzeSentimentResponse response = languageServiceClient.analyzeSentiment(document, encodingType);
+   * }
+   * 
+ * + * @param document Input document. + * @param encodingType The encoding type used by the API to calculate sentence offsets. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final AnalyzeSentimentResponse analyzeSentiment( + Document document, EncodingType encodingType) { + + AnalyzeSentimentRequest request = + AnalyzeSentimentRequest.newBuilder() + .setDocument(document) + .setEncodingType(encodingType) + .build(); + return analyzeSentiment(request); + } + // AUTO-GENERATED DOCUMENTATION AND METHOD /** * Analyzes the sentiment of the provided text. @@ -245,6 +275,30 @@ public final AnalyzeEntitiesResponse analyzeEntities( return analyzeEntities(request); } + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Finds named entities (currently proper names and common nouns) in the text along with entity + * types, salience, mentions for each entity, and other properties. + * + *

Sample code: + * + *


+   * try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
+   *   Document document = Document.newBuilder().build();
+   *   AnalyzeEntitiesResponse response = languageServiceClient.analyzeEntities(document);
+   * }
+   * 
+ * + * @param document Input document. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final AnalyzeEntitiesResponse analyzeEntities(Document document) { + + AnalyzeEntitiesRequest request = + AnalyzeEntitiesRequest.newBuilder().setDocument(document).build(); + return analyzeEntities(request); + } + // AUTO-GENERATED DOCUMENTATION AND METHOD /** * Finds named entities (currently proper names and common nouns) in the text along with entity @@ -324,6 +378,31 @@ public final AnalyzeEntitySentimentResponse analyzeEntitySentiment( return analyzeEntitySentiment(request); } + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Finds entities, similar to + * [AnalyzeEntities][google.cloud.language.v1.LanguageService.AnalyzeEntities] in the text and + * analyzes sentiment associated with each entity and its mentions. + * + *

Sample code: + * + *


+   * try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
+   *   Document document = Document.newBuilder().build();
+   *   AnalyzeEntitySentimentResponse response = languageServiceClient.analyzeEntitySentiment(document);
+   * }
+   * 
+ * + * @param document Input document. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final AnalyzeEntitySentimentResponse analyzeEntitySentiment(Document document) { + + AnalyzeEntitySentimentRequest request = + AnalyzeEntitySentimentRequest.newBuilder().setDocument(document).build(); + return analyzeEntitySentiment(request); + } + // AUTO-GENERATED DOCUMENTATION AND METHOD /** * Finds entities, similar to @@ -404,6 +483,29 @@ public final AnalyzeSyntaxResponse analyzeSyntax(Document document, EncodingType return analyzeSyntax(request); } + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Analyzes the syntax of the text and provides sentence boundaries and tokenization along with + * part of speech tags, dependency trees, and other properties. + * + *

Sample code: + * + *


+   * try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
+   *   Document document = Document.newBuilder().build();
+   *   AnalyzeSyntaxResponse response = languageServiceClient.analyzeSyntax(document);
+   * }
+   * 
+ * + * @param document Input document. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final AnalyzeSyntaxResponse analyzeSyntax(Document document) { + + AnalyzeSyntaxRequest request = AnalyzeSyntaxRequest.newBuilder().setDocument(document).build(); + return analyzeSyntax(request); + } + // AUTO-GENERATED DOCUMENTATION AND METHOD /** * Analyzes the syntax of the text and provides sentence boundaries and tokenization along with @@ -551,6 +653,33 @@ public final AnnotateTextResponse annotateText( return annotateText(request); } + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * A convenience method that provides all the features that analyzeSentiment, analyzeEntities, and + * analyzeSyntax provide in one call. + * + *

Sample code: + * + *


+   * try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
+   *   Document document = Document.newBuilder().build();
+   *   AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().build();
+   *   AnnotateTextResponse response = languageServiceClient.annotateText(document, features);
+   * }
+   * 
+ * + * @param document Input document. + * @param features The enabled features. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final AnnotateTextResponse annotateText( + Document document, AnnotateTextRequest.Features features) { + + AnnotateTextRequest request = + AnnotateTextRequest.newBuilder().setDocument(document).setFeatures(features).build(); + return annotateText(request); + } + // AUTO-GENERATED DOCUMENTATION AND METHOD /** * A convenience method that provides all the features that analyzeSentiment, analyzeEntities, and diff --git a/google-cloud-clients/google-cloud-language/src/main/java/com/google/cloud/language/v1/package-info.java b/google-cloud-clients/google-cloud-language/src/main/java/com/google/cloud/language/v1/package-info.java index 410ff1248de4..2cf6aeec113f 100644 --- a/google-cloud-clients/google-cloud-language/src/main/java/com/google/cloud/language/v1/package-info.java +++ b/google-cloud-clients/google-cloud-language/src/main/java/com/google/cloud/language/v1/package-info.java @@ -30,7 +30,8 @@ * * try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) { * Document document = Document.newBuilder().build(); - * AnalyzeSentimentResponse response = languageServiceClient.analyzeSentiment(document); + * EncodingType encodingType = EncodingType.NONE; + * AnalyzeSentimentResponse response = languageServiceClient.analyzeSentiment(document, encodingType); * } * * diff --git a/google-cloud-clients/google-cloud-language/src/test/java/com/google/cloud/language/v1/LanguageServiceClientTest.java b/google-cloud-clients/google-cloud-language/src/test/java/com/google/cloud/language/v1/LanguageServiceClientTest.java index f02c92c5e098..1541fa1851cc 100644 --- a/google-cloud-clients/google-cloud-language/src/test/java/com/google/cloud/language/v1/LanguageServiceClientTest.java +++ b/google-cloud-clients/google-cloud-language/src/test/java/com/google/cloud/language/v1/LanguageServiceClientTest.java @@ -81,8 +81,9 @@ public void analyzeSentimentTest() { mockLanguageService.addResponse(expectedResponse); Document document = Document.newBuilder().build(); + EncodingType encodingType = EncodingType.NONE; - AnalyzeSentimentResponse actualResponse = client.analyzeSentiment(document); + AnalyzeSentimentResponse actualResponse = client.analyzeSentiment(document, encodingType); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockLanguageService.getRequests(); @@ -90,6 +91,7 @@ public void analyzeSentimentTest() { AnalyzeSentimentRequest actualRequest = (AnalyzeSentimentRequest) actualRequests.get(0); Assert.assertEquals(document, actualRequest.getDocument()); + Assert.assertEquals(encodingType, actualRequest.getEncodingType()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), @@ -102,6 +104,47 @@ public void analyzeSentimentExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockLanguageService.addException(exception); + try { + Document document = Document.newBuilder().build(); + EncodingType encodingType = EncodingType.NONE; + + client.analyzeSentiment(document, encodingType); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } + + @Test + @SuppressWarnings("all") + public void analyzeSentimentTest2() { + String language = "language-1613589672"; + AnalyzeSentimentResponse expectedResponse = + AnalyzeSentimentResponse.newBuilder().setLanguage(language).build(); + mockLanguageService.addResponse(expectedResponse); + + Document document = Document.newBuilder().build(); + + AnalyzeSentimentResponse actualResponse = client.analyzeSentiment(document); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockLanguageService.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + AnalyzeSentimentRequest actualRequest = (AnalyzeSentimentRequest) actualRequests.get(0); + + Assert.assertEquals(document, actualRequest.getDocument()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + @SuppressWarnings("all") + public void analyzeSentimentExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockLanguageService.addException(exception); + try { Document document = Document.newBuilder().build(); @@ -155,6 +198,46 @@ public void analyzeEntitiesExceptionTest() throws Exception { } } + @Test + @SuppressWarnings("all") + public void analyzeEntitiesTest2() { + String language = "language-1613589672"; + AnalyzeEntitiesResponse expectedResponse = + AnalyzeEntitiesResponse.newBuilder().setLanguage(language).build(); + mockLanguageService.addResponse(expectedResponse); + + Document document = Document.newBuilder().build(); + + AnalyzeEntitiesResponse actualResponse = client.analyzeEntities(document); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockLanguageService.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + AnalyzeEntitiesRequest actualRequest = (AnalyzeEntitiesRequest) actualRequests.get(0); + + Assert.assertEquals(document, actualRequest.getDocument()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + @SuppressWarnings("all") + public void analyzeEntitiesExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockLanguageService.addException(exception); + + try { + Document document = Document.newBuilder().build(); + + client.analyzeEntities(document); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } + @Test @SuppressWarnings("all") public void analyzeEntitySentimentTest() { @@ -200,6 +283,47 @@ public void analyzeEntitySentimentExceptionTest() throws Exception { } } + @Test + @SuppressWarnings("all") + public void analyzeEntitySentimentTest2() { + String language = "language-1613589672"; + AnalyzeEntitySentimentResponse expectedResponse = + AnalyzeEntitySentimentResponse.newBuilder().setLanguage(language).build(); + mockLanguageService.addResponse(expectedResponse); + + Document document = Document.newBuilder().build(); + + AnalyzeEntitySentimentResponse actualResponse = client.analyzeEntitySentiment(document); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockLanguageService.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + AnalyzeEntitySentimentRequest actualRequest = + (AnalyzeEntitySentimentRequest) actualRequests.get(0); + + Assert.assertEquals(document, actualRequest.getDocument()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + @SuppressWarnings("all") + public void analyzeEntitySentimentExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockLanguageService.addException(exception); + + try { + Document document = Document.newBuilder().build(); + + client.analyzeEntitySentiment(document); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } + @Test @SuppressWarnings("all") public void analyzeSyntaxTest() { @@ -243,6 +367,46 @@ public void analyzeSyntaxExceptionTest() throws Exception { } } + @Test + @SuppressWarnings("all") + public void analyzeSyntaxTest2() { + String language = "language-1613589672"; + AnalyzeSyntaxResponse expectedResponse = + AnalyzeSyntaxResponse.newBuilder().setLanguage(language).build(); + mockLanguageService.addResponse(expectedResponse); + + Document document = Document.newBuilder().build(); + + AnalyzeSyntaxResponse actualResponse = client.analyzeSyntax(document); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockLanguageService.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + AnalyzeSyntaxRequest actualRequest = (AnalyzeSyntaxRequest) actualRequests.get(0); + + Assert.assertEquals(document, actualRequest.getDocument()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + @SuppressWarnings("all") + public void analyzeSyntaxExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockLanguageService.addException(exception); + + try { + Document document = Document.newBuilder().build(); + + client.analyzeSyntax(document); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } + @Test @SuppressWarnings("all") public void classifyTextTest() { @@ -326,4 +490,47 @@ public void annotateTextExceptionTest() throws Exception { // Expected exception } } + + @Test + @SuppressWarnings("all") + public void annotateTextTest2() { + String language = "language-1613589672"; + AnnotateTextResponse expectedResponse = + AnnotateTextResponse.newBuilder().setLanguage(language).build(); + mockLanguageService.addResponse(expectedResponse); + + Document document = Document.newBuilder().build(); + AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().build(); + + AnnotateTextResponse actualResponse = client.annotateText(document, features); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockLanguageService.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + AnnotateTextRequest actualRequest = (AnnotateTextRequest) actualRequests.get(0); + + Assert.assertEquals(document, actualRequest.getDocument()); + Assert.assertEquals(features, actualRequest.getFeatures()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + @SuppressWarnings("all") + public void annotateTextExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockLanguageService.addException(exception); + + try { + Document document = Document.newBuilder().build(); + AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().build(); + + client.annotateText(document, features); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } } diff --git a/google-cloud-clients/google-cloud-language/synth.metadata b/google-cloud-clients/google-cloud-language/synth.metadata index 0dedf349525a..612dcf2983e2 100644 --- a/google-cloud-clients/google-cloud-language/synth.metadata +++ b/google-cloud-clients/google-cloud-language/synth.metadata @@ -1,19 +1,19 @@ { - "updateTime": "2019-04-04T07:47:40.894268Z", + "updateTime": "2019-04-06T07:47:58.547907Z", "sources": [ { "generator": { "name": "artman", - "version": "0.16.23", - "dockerImage": "googleapis/artman@sha256:f3a3f88000dc1cd1b4826104c5574aa5c534f6793fbf66e888d11c0d7ef5762e" + "version": "0.16.25", + "dockerImage": "googleapis/artman@sha256:d9597f983d1d4e61272c63cb97b7d8f8234da9999526c35d357de3d781f0ec1b" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "04193ea2f8121388c998ab49c382f2c03417dcce", - "internalRef": "241828309" + "sha": "9a02c5acecb43f38fae4fa52c6420f21c335b888", + "internalRef": "242170119" } } ],