Sample code: * @@ -268,8 +268,8 @@ public final AnalyzeEntitiesResponse analyzeEntities( // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Finds named entities (currently finds proper names) in the text, entity types, salience, - * mentions for each entity, and other properties. + * 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: * @@ -294,8 +294,8 @@ public final AnalyzeEntitiesResponse analyzeEntities(AnalyzeEntitiesRequest requ // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Finds named entities (currently finds proper names) in the text, entity types, salience, - * mentions for each entity, and other properties. + * 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: * diff --git a/google-cloud-language/src/main/java/com/google/cloud/language/spi/v1beta2/LanguageServiceClient.java b/google-cloud-language/src/main/java/com/google/cloud/language/spi/v1beta2/LanguageServiceClient.java new file mode 100644 index 000000000000..06ae5526a0f1 --- /dev/null +++ b/google-cloud-language/src/main/java/com/google/cloud/language/spi/v1beta2/LanguageServiceClient.java @@ -0,0 +1,589 @@ +/* + * Copyright 2017, Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.language.spi.v1beta2; + +import com.google.api.gax.grpc.ChannelAndExecutor; +import com.google.api.gax.grpc.UnaryCallable; +import com.google.cloud.language.v1beta2.AnalyzeEntitiesRequest; +import com.google.cloud.language.v1beta2.AnalyzeEntitiesResponse; +import com.google.cloud.language.v1beta2.AnalyzeEntitySentimentRequest; +import com.google.cloud.language.v1beta2.AnalyzeEntitySentimentResponse; +import com.google.cloud.language.v1beta2.AnalyzeSentimentRequest; +import com.google.cloud.language.v1beta2.AnalyzeSentimentResponse; +import com.google.cloud.language.v1beta2.AnalyzeSyntaxRequest; +import com.google.cloud.language.v1beta2.AnalyzeSyntaxResponse; +import com.google.cloud.language.v1beta2.AnnotateTextRequest; +import com.google.cloud.language.v1beta2.AnnotateTextRequest.Features; +import com.google.cloud.language.v1beta2.AnnotateTextResponse; +import com.google.cloud.language.v1beta2.Document; +import com.google.cloud.language.v1beta2.EncodingType; +import com.google.protobuf.ExperimentalApi; +import io.grpc.ManagedChannel; +import java.io.Closeable; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ScheduledExecutorService; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND SERVICE +/** + * Service Description: Provides text analysis operations such as sentiment analysis and entity + * recognition. + * + *
This class provides the ability to make remote calls to the backing service through method + * calls that map to API methods. Sample code to get started: + * + *
+ *
+ * try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
+ * Document document = Document.newBuilder().build();
+ * AnalyzeSentimentResponse response = languageServiceClient.analyzeSentiment(document);
+ * }
+ *
+ *
+ *
+ * Note: close() needs to be called on the languageServiceClient object to clean up resources + * such as threads. In the example above, try-with-resources is used, which automatically calls + * close(). + * + *
The surface of this class includes several types of Java methods for each of the API's + * methods: + * + *
See the individual methods for example code. + * + *
Many parameters require resource names to be formatted in a particular way. To assist with + * these names, this class includes a format method for each type of name, and additionally a parse + * method to extract the individual identifiers contained within names that are returned. + * + *
This class can be customized by passing in a custom instance of LanguageServiceSettings to + * create(). For example: + * + *
+ *
+ * InstantiatingChannelProvider channelProvider =
+ * LanguageServiceSettings.defaultChannelProviderBuilder()
+ * .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
+ * .build();
+ * LanguageServiceSettings languageServiceSettings =
+ * LanguageServiceSettings.defaultBuilder().setChannelProvider(channelProvider).build();
+ * LanguageServiceClient languageServiceClient =
+ * LanguageServiceClient.create(languageServiceSettings);
+ *
+ *
+ */
+@Generated("by GAPIC")
+@ExperimentalApi
+public class LanguageServiceClient implements AutoCloseable {
+ private final LanguageServiceSettings settings;
+ private final ScheduledExecutorService executor;
+ private final ManagedChannel channel;
+ private final ListSample code: + * + *
+ * try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
+ * Document document = Document.newBuilder().build();
+ * AnalyzeSentimentResponse response = languageServiceClient.analyzeSentiment(document);
+ * }
+ *
+ *
+ * @param document Input document. Currently, `analyzeSentiment` only supports English text
+ * ([Document.language][google.cloud.language.v1beta2.Document.language]="EN").
+ * @throws com.google.api.gax.grpc.ApiException if the remote call fails
+ */
+ public final AnalyzeSentimentResponse analyzeSentiment(Document document) {
+
+ AnalyzeSentimentRequest request =
+ AnalyzeSentimentRequest.newBuilder().setDocument(document).build();
+ return analyzeSentiment(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD
+ /**
+ * Analyzes the sentiment of the provided text.
+ *
+ * Sample code: + * + *
+ * try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
+ * Document document = Document.newBuilder().build();
+ * AnalyzeSentimentRequest request = AnalyzeSentimentRequest.newBuilder()
+ * .setDocument(document)
+ * .build();
+ * AnalyzeSentimentResponse response = languageServiceClient.analyzeSentiment(request);
+ * }
+ *
+ *
+ * @param request The request object containing all of the parameters for the API call.
+ * @throws com.google.api.gax.grpc.ApiException if the remote call fails
+ */
+ private final AnalyzeSentimentResponse analyzeSentiment(AnalyzeSentimentRequest request) {
+ return analyzeSentimentCallable().call(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD
+ /**
+ * Analyzes the sentiment of the provided text.
+ *
+ * Sample code: + * + *
+ * try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
+ * Document document = Document.newBuilder().build();
+ * AnalyzeSentimentRequest request = AnalyzeSentimentRequest.newBuilder()
+ * .setDocument(document)
+ * .build();
+ * ApiFuture<AnalyzeSentimentResponse> future = languageServiceClient.analyzeSentimentCallable().futureCall(request);
+ * // Do something
+ * AnalyzeSentimentResponse response = future.get();
+ * }
+ *
+ */
+ public final UnaryCallableSample code: + * + *
+ * try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
+ * Document document = Document.newBuilder().build();
+ * EncodingType encodingType = EncodingType.NONE;
+ * AnalyzeEntitiesResponse response = languageServiceClient.analyzeEntities(document, encodingType);
+ * }
+ *
+ *
+ * @param document Input document.
+ * @param encodingType The encoding type used by the API to calculate offsets.
+ * @throws com.google.api.gax.grpc.ApiException if the remote call fails
+ */
+ public final AnalyzeEntitiesResponse analyzeEntities(
+ Document document, EncodingType encodingType) {
+
+ AnalyzeEntitiesRequest request =
+ AnalyzeEntitiesRequest.newBuilder()
+ .setDocument(document)
+ .setEncodingType(encodingType)
+ .build();
+ 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();
+ * EncodingType encodingType = EncodingType.NONE;
+ * AnalyzeEntitiesRequest request = AnalyzeEntitiesRequest.newBuilder()
+ * .setDocument(document)
+ * .setEncodingType(encodingType)
+ * .build();
+ * AnalyzeEntitiesResponse response = languageServiceClient.analyzeEntities(request);
+ * }
+ *
+ *
+ * @param request The request object containing all of the parameters for the API call.
+ * @throws com.google.api.gax.grpc.ApiException if the remote call fails
+ */
+ public final AnalyzeEntitiesResponse analyzeEntities(AnalyzeEntitiesRequest request) {
+ return analyzeEntitiesCallable().call(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();
+ * EncodingType encodingType = EncodingType.NONE;
+ * AnalyzeEntitiesRequest request = AnalyzeEntitiesRequest.newBuilder()
+ * .setDocument(document)
+ * .setEncodingType(encodingType)
+ * .build();
+ * ApiFuture<AnalyzeEntitiesResponse> future = languageServiceClient.analyzeEntitiesCallable().futureCall(request);
+ * // Do something
+ * AnalyzeEntitiesResponse response = future.get();
+ * }
+ *
+ */
+ public final UnaryCallableSample code: + * + *
+ * try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
+ * Document document = Document.newBuilder().build();
+ * EncodingType encodingType = EncodingType.NONE;
+ * AnalyzeEntitySentimentResponse response = languageServiceClient.analyzeEntitySentiment(document, encodingType);
+ * }
+ *
+ *
+ * @param document Input document.
+ * @param encodingType The encoding type used by the API to calculate offsets.
+ * @throws com.google.api.gax.grpc.ApiException if the remote call fails
+ */
+ public final AnalyzeEntitySentimentResponse analyzeEntitySentiment(
+ Document document, EncodingType encodingType) {
+
+ AnalyzeEntitySentimentRequest request =
+ AnalyzeEntitySentimentRequest.newBuilder()
+ .setDocument(document)
+ .setEncodingType(encodingType)
+ .build();
+ return analyzeEntitySentiment(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD
+ /**
+ * Finds entities, similar to
+ * [AnalyzeEntities][google.cloud.language.v1beta2.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();
+ * EncodingType encodingType = EncodingType.NONE;
+ * AnalyzeEntitySentimentRequest request = AnalyzeEntitySentimentRequest.newBuilder()
+ * .setDocument(document)
+ * .setEncodingType(encodingType)
+ * .build();
+ * AnalyzeEntitySentimentResponse response = languageServiceClient.analyzeEntitySentiment(request);
+ * }
+ *
+ *
+ * @param request The request object containing all of the parameters for the API call.
+ * @throws com.google.api.gax.grpc.ApiException if the remote call fails
+ */
+ public final AnalyzeEntitySentimentResponse analyzeEntitySentiment(
+ AnalyzeEntitySentimentRequest request) {
+ return analyzeEntitySentimentCallable().call(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD
+ /**
+ * Finds entities, similar to
+ * [AnalyzeEntities][google.cloud.language.v1beta2.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();
+ * EncodingType encodingType = EncodingType.NONE;
+ * AnalyzeEntitySentimentRequest request = AnalyzeEntitySentimentRequest.newBuilder()
+ * .setDocument(document)
+ * .setEncodingType(encodingType)
+ * .build();
+ * ApiFuture<AnalyzeEntitySentimentResponse> future = languageServiceClient.analyzeEntitySentimentCallable().futureCall(request);
+ * // Do something
+ * AnalyzeEntitySentimentResponse response = future.get();
+ * }
+ *
+ */
+ public final UnaryCallableSample code: + * + *
+ * try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
+ * Document document = Document.newBuilder().build();
+ * EncodingType encodingType = EncodingType.NONE;
+ * AnalyzeSyntaxResponse response = languageServiceClient.analyzeSyntax(document, encodingType);
+ * }
+ *
+ *
+ * @param document Input document.
+ * @param encodingType The encoding type used by the API to calculate offsets.
+ * @throws com.google.api.gax.grpc.ApiException if the remote call fails
+ */
+ public final AnalyzeSyntaxResponse analyzeSyntax(Document document, EncodingType encodingType) {
+
+ AnalyzeSyntaxRequest request =
+ AnalyzeSyntaxRequest.newBuilder()
+ .setDocument(document)
+ .setEncodingType(encodingType)
+ .build();
+ 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();
+ * EncodingType encodingType = EncodingType.NONE;
+ * AnalyzeSyntaxRequest request = AnalyzeSyntaxRequest.newBuilder()
+ * .setDocument(document)
+ * .setEncodingType(encodingType)
+ * .build();
+ * AnalyzeSyntaxResponse response = languageServiceClient.analyzeSyntax(request);
+ * }
+ *
+ *
+ * @param request The request object containing all of the parameters for the API call.
+ * @throws com.google.api.gax.grpc.ApiException if the remote call fails
+ */
+ public final AnalyzeSyntaxResponse analyzeSyntax(AnalyzeSyntaxRequest request) {
+ return analyzeSyntaxCallable().call(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();
+ * EncodingType encodingType = EncodingType.NONE;
+ * AnalyzeSyntaxRequest request = AnalyzeSyntaxRequest.newBuilder()
+ * .setDocument(document)
+ * .setEncodingType(encodingType)
+ * .build();
+ * ApiFuture<AnalyzeSyntaxResponse> future = languageServiceClient.analyzeSyntaxCallable().futureCall(request);
+ * // Do something
+ * AnalyzeSyntaxResponse response = future.get();
+ * }
+ *
+ */
+ public final UnaryCallableSample code: + * + *
+ * try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
+ * Document document = Document.newBuilder().build();
+ * AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().build();
+ * EncodingType encodingType = EncodingType.NONE;
+ * AnnotateTextResponse response = languageServiceClient.annotateText(document, features, encodingType);
+ * }
+ *
+ *
+ * @param document Input document.
+ * @param features The enabled features.
+ * @param encodingType The encoding type used by the API to calculate offsets.
+ * @throws com.google.api.gax.grpc.ApiException if the remote call fails
+ */
+ public final AnnotateTextResponse annotateText(
+ Document document, AnnotateTextRequest.Features features, EncodingType encodingType) {
+
+ AnnotateTextRequest request =
+ AnnotateTextRequest.newBuilder()
+ .setDocument(document)
+ .setFeatures(features)
+ .setEncodingType(encodingType)
+ .build();
+ return annotateText(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD
+ /**
+ * A convenience method that provides all syntax, sentiment, and entity features in one call.
+ *
+ * Sample code: + * + *
+ * try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
+ * Document document = Document.newBuilder().build();
+ * AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().build();
+ * EncodingType encodingType = EncodingType.NONE;
+ * AnnotateTextRequest request = AnnotateTextRequest.newBuilder()
+ * .setDocument(document)
+ * .setFeatures(features)
+ * .setEncodingType(encodingType)
+ * .build();
+ * AnnotateTextResponse response = languageServiceClient.annotateText(request);
+ * }
+ *
+ *
+ * @param request The request object containing all of the parameters for the API call.
+ * @throws com.google.api.gax.grpc.ApiException if the remote call fails
+ */
+ public final AnnotateTextResponse annotateText(AnnotateTextRequest request) {
+ return annotateTextCallable().call(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD
+ /**
+ * A convenience method that provides all syntax, sentiment, and entity features in one call.
+ *
+ * Sample code: + * + *
+ * try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
+ * Document document = Document.newBuilder().build();
+ * AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().build();
+ * EncodingType encodingType = EncodingType.NONE;
+ * AnnotateTextRequest request = AnnotateTextRequest.newBuilder()
+ * .setDocument(document)
+ * .setFeatures(features)
+ * .setEncodingType(encodingType)
+ * .build();
+ * ApiFuture<AnnotateTextResponse> future = languageServiceClient.annotateTextCallable().futureCall(request);
+ * // Do something
+ * AnnotateTextResponse response = future.get();
+ * }
+ *
+ */
+ public final UnaryCallableThe default instance has everything set to sensible defaults: + * + *
The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. For + * example, to set the total timeout of analyzeSentiment to 30 seconds: + * + *
+ *
+ * LanguageServiceSettings.Builder languageServiceSettingsBuilder =
+ * LanguageServiceSettings.defaultBuilder();
+ * languageServiceSettingsBuilder.analyzeSentimentSettings().getRetrySettingsBuilder()
+ * .setTotalTimeout(Duration.standardSeconds(30));
+ * LanguageServiceSettings languageServiceSettings = languageServiceSettingsBuilder.build();
+ *
+ *
+ */
+@Generated("by GAPIC v0.0.5")
+@ExperimentalApi
+public class LanguageServiceSettings extends ClientSettings {
+ /** The default address of the service. */
+ private static final String DEFAULT_SERVICE_ADDRESS = "language.googleapis.com";
+
+ /** The default port of the service. */
+ private static final int DEFAULT_SERVICE_PORT = 443;
+
+ /** The default scopes of the service. */
+ private static final ImmutableListNote: This method does not support applying settings to streaming methods.
+ */
+ public Builder applyToAllUnaryMethods(UnaryCallSettings.Builder unaryCallSettings)
+ throws Exception {
+ super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, unaryCallSettings);
+ return this;
+ }
+
+ /** Returns the builder for the settings used for calls to analyzeSentiment. */
+ public SimpleCallSettings.Builder The interfaces provided are listed below, along with usage samples.
+ *
+ * ===================== LanguageServiceClient =====================
+ *
+ * Service Description: Provides text analysis operations such as sentiment analysis and entity
+ * recognition.
+ *
+ * Sample for LanguageServiceClient:
+ *
+ *
+ *
+ */
+package com.google.cloud.language.spi.v1beta2;
diff --git a/google-cloud-language/src/test/java/com/google/cloud/language/spi/v1beta2/LanguageServiceClientTest.java b/google-cloud-language/src/test/java/com/google/cloud/language/spi/v1beta2/LanguageServiceClientTest.java
new file mode 100644
index 000000000000..b0c4c5969c4b
--- /dev/null
+++ b/google-cloud-language/src/test/java/com/google/cloud/language/spi/v1beta2/LanguageServiceClientTest.java
@@ -0,0 +1,277 @@
+/*
+ * Copyright 2017, Google Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.google.cloud.language.spi.v1beta2;
+
+import com.google.api.gax.grpc.ApiException;
+import com.google.api.gax.testing.MockGrpcService;
+import com.google.api.gax.testing.MockServiceHelper;
+import com.google.cloud.language.v1beta2.AnalyzeEntitiesRequest;
+import com.google.cloud.language.v1beta2.AnalyzeEntitiesResponse;
+import com.google.cloud.language.v1beta2.AnalyzeEntitySentimentRequest;
+import com.google.cloud.language.v1beta2.AnalyzeEntitySentimentResponse;
+import com.google.cloud.language.v1beta2.AnalyzeSentimentRequest;
+import com.google.cloud.language.v1beta2.AnalyzeSentimentResponse;
+import com.google.cloud.language.v1beta2.AnalyzeSyntaxRequest;
+import com.google.cloud.language.v1beta2.AnalyzeSyntaxResponse;
+import com.google.cloud.language.v1beta2.AnnotateTextRequest;
+import com.google.cloud.language.v1beta2.AnnotateTextRequest.Features;
+import com.google.cloud.language.v1beta2.AnnotateTextResponse;
+import com.google.cloud.language.v1beta2.Document;
+import com.google.cloud.language.v1beta2.EncodingType;
+import com.google.protobuf.GeneratedMessageV3;
+import io.grpc.Status;
+import io.grpc.StatusRuntimeException;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+@javax.annotation.Generated("by GAPIC")
+public class LanguageServiceClientTest {
+ private static MockLanguageService mockLanguageService;
+ private static MockServiceHelper serviceHelper;
+ private LanguageServiceClient client;
+
+ @BeforeClass
+ public static void startStaticServer() {
+ mockLanguageService = new MockLanguageService();
+ serviceHelper =
+ new MockServiceHelper("in-process-1", Arrays.
+ * try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
+ * Document document = Document.newBuilder().build();
+ * AnalyzeSentimentResponse response = languageServiceClient.analyzeSentiment(document);
+ * }
+ *
+ *