class Google::Cloud::Language::V1beta2::LanguageService::Client
Client
for the LanguageService
service.
Provides text analysis operations such as sentiment analysis and entity recognition.
Attributes
@private
Public Class Methods
Configure the LanguageService
Client
class.
See {::Google::Cloud::Language::V1beta2::LanguageService::Client::Configuration} for a description of the configuration fields.
@example
# Modify the configuration for all LanguageService clients ::Google::Cloud::Language::V1beta2::LanguageService::Client.configure do |config| config.timeout = 10.0 end
@yield [config] Configure the Client
client. @yieldparam config [Client::Configuration]
@return [Client::Configuration]
# File lib/google/cloud/language/v1beta2/language_service/client.rb, line 55 def self.configure @configure ||= begin namespace = ["Google", "Cloud", "Language", "V1beta2"] parent_config = while namespace.any? parent_name = namespace.join "::" parent_const = const_get parent_name break parent_const.configure if parent_const.respond_to? :configure namespace.pop end default_config = Client::Configuration.new parent_config default_config.rpcs.analyze_sentiment.timeout = 600.0 default_config.rpcs.analyze_sentiment.retry_policy = { initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [14, 4] } default_config.rpcs.analyze_entities.timeout = 600.0 default_config.rpcs.analyze_entities.retry_policy = { initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [14, 4] } default_config.rpcs.analyze_entity_sentiment.timeout = 600.0 default_config.rpcs.analyze_entity_sentiment.retry_policy = { initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [14, 4] } default_config.rpcs.analyze_syntax.timeout = 600.0 default_config.rpcs.analyze_syntax.retry_policy = { initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [14, 4] } default_config.rpcs.classify_text.timeout = 600.0 default_config.rpcs.classify_text.retry_policy = { initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [14, 4] } default_config.rpcs.annotate_text.timeout = 600.0 default_config.rpcs.annotate_text.retry_policy = { initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [14, 4] } default_config end yield @configure if block_given? @configure end
Create a new LanguageService
client object.
@example
# Create a client using the default configuration client = ::Google::Cloud::Language::V1beta2::LanguageService::Client.new # Create a client using a custom configuration client = ::Google::Cloud::Language::V1beta2::LanguageService::Client.new do |config| config.timeout = 10.0 end
@yield [config] Configure the LanguageService
client. @yieldparam config [Client::Configuration]
# File lib/google/cloud/language/v1beta2/language_service/client.rb, line 138 def initialize # These require statements are intentionally placed here to initialize # the gRPC module only when it's required. # See https://github.com/googleapis/toolkit/issues/446 require "gapic/grpc" require "google/cloud/language/v1beta2/language_service_services_pb" # Create the configuration object @config = Configuration.new Client.configure # Yield the configuration if needed yield @config if block_given? # Create credentials credentials = @config.credentials # Use self-signed JWT if the endpoint is unchanged from default, # but only if the default endpoint does not have a region prefix. enable_self_signed_jwt = @config.endpoint == Client.configure.endpoint && !@config.endpoint.split(".").first.include?("-") credentials ||= Credentials.default scope: @config.scope, enable_self_signed_jwt: enable_self_signed_jwt if credentials.is_a?(::String) || credentials.is_a?(::Hash) credentials = Credentials.new credentials, scope: @config.scope end @quota_project_id = @config.quota_project @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id @language_service_stub = ::Gapic::ServiceStub.new( ::Google::Cloud::Language::V1beta2::LanguageService::Stub, credentials: credentials, endpoint: @config.endpoint, channel_args: @config.channel_args, interceptors: @config.interceptors ) end
Public Instance Methods
Finds named entities (currently proper names and common nouns) in the text along with entity types, salience, mentions for each entity, and other properties.
@overload analyze_entities
(request, options = nil)
Pass arguments to `analyze_entities` via a request object, either of type {::Google::Cloud::Language::V1beta2::AnalyzeEntitiesRequest} or an equivalent Hash. @param request [::Google::Cloud::Language::V1beta2::AnalyzeEntitiesRequest, ::Hash] A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload analyze_entities
(document: nil, encoding_type: nil)
Pass arguments to `analyze_entities` via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above). @param document [::Google::Cloud::Language::V1beta2::Document, ::Hash] Required. Input document. @param encoding_type [::Google::Cloud::Language::V1beta2::EncodingType] The encoding type used by the API to calculate offsets.
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Language::V1beta2::AnalyzeEntitiesResponse] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Google::Cloud::Language::V1beta2::AnalyzeEntitiesResponse]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/language/v1beta2/language_service/client.rb, line 274 def analyze_entities request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V1beta2::AnalyzeEntitiesRequest # Converts hash and nil to an options object options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults metadata = @config.rpcs.analyze_entities.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Language::V1beta2::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.analyze_entities.timeout, metadata: metadata, retry_policy: @config.rpcs.analyze_entities.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @language_service_stub.call_rpc :analyze_entities, request, options: options do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end
Finds entities, similar to {::Google::Cloud::Language::V1beta2::LanguageService::Client#analyze_entities AnalyzeEntities} in the text and analyzes sentiment associated with each entity and its mentions.
@overload analyze_entity_sentiment
(request, options = nil)
Pass arguments to `analyze_entity_sentiment` via a request object, either of type {::Google::Cloud::Language::V1beta2::AnalyzeEntitySentimentRequest} or an equivalent Hash. @param request [::Google::Cloud::Language::V1beta2::AnalyzeEntitySentimentRequest, ::Hash] A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload analyze_entity_sentiment
(document: nil, encoding_type: nil)
Pass arguments to `analyze_entity_sentiment` via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above). @param document [::Google::Cloud::Language::V1beta2::Document, ::Hash] Required. Input document. @param encoding_type [::Google::Cloud::Language::V1beta2::EncodingType] The encoding type used by the API to calculate offsets.
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Language::V1beta2::AnalyzeEntitySentimentResponse] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Google::Cloud::Language::V1beta2::AnalyzeEntitySentimentResponse]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/language/v1beta2/language_service/client.rb, line 339 def analyze_entity_sentiment request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V1beta2::AnalyzeEntitySentimentRequest # Converts hash and nil to an options object options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults metadata = @config.rpcs.analyze_entity_sentiment.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Language::V1beta2::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.analyze_entity_sentiment.timeout, metadata: metadata, retry_policy: @config.rpcs.analyze_entity_sentiment.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @language_service_stub.call_rpc :analyze_entity_sentiment, request, options: options do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end
Analyzes the sentiment of the provided text.
@overload analyze_sentiment
(request, options = nil)
Pass arguments to `analyze_sentiment` via a request object, either of type {::Google::Cloud::Language::V1beta2::AnalyzeSentimentRequest} or an equivalent Hash. @param request [::Google::Cloud::Language::V1beta2::AnalyzeSentimentRequest, ::Hash] A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload analyze_sentiment
(document: nil, encoding_type: nil)
Pass arguments to `analyze_sentiment` via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above). @param document [::Google::Cloud::Language::V1beta2::Document, ::Hash] Required. Input document. @param encoding_type [::Google::Cloud::Language::V1beta2::EncodingType] The encoding type used by the API to calculate sentence offsets for the sentence sentiment.
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Language::V1beta2::AnalyzeSentimentResponse] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Google::Cloud::Language::V1beta2::AnalyzeSentimentResponse]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/language/v1beta2/language_service/client.rb, line 208 def analyze_sentiment request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V1beta2::AnalyzeSentimentRequest # Converts hash and nil to an options object options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults metadata = @config.rpcs.analyze_sentiment.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Language::V1beta2::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.analyze_sentiment.timeout, metadata: metadata, retry_policy: @config.rpcs.analyze_sentiment.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @language_service_stub.call_rpc :analyze_sentiment, request, options: options do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end
Analyzes the syntax of the text and provides sentence boundaries and tokenization along with part-of-speech tags, dependency trees, and other properties.
@overload analyze_syntax
(request, options = nil)
Pass arguments to `analyze_syntax` via a request object, either of type {::Google::Cloud::Language::V1beta2::AnalyzeSyntaxRequest} or an equivalent Hash. @param request [::Google::Cloud::Language::V1beta2::AnalyzeSyntaxRequest, ::Hash] A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload analyze_syntax
(document: nil, encoding_type: nil)
Pass arguments to `analyze_syntax` via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above). @param document [::Google::Cloud::Language::V1beta2::Document, ::Hash] Required. Input document. @param encoding_type [::Google::Cloud::Language::V1beta2::EncodingType] The encoding type used by the API to calculate offsets.
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Language::V1beta2::AnalyzeSyntaxResponse] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Google::Cloud::Language::V1beta2::AnalyzeSyntaxResponse]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/language/v1beta2/language_service/client.rb, line 405 def analyze_syntax request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V1beta2::AnalyzeSyntaxRequest # Converts hash and nil to an options object options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults metadata = @config.rpcs.analyze_syntax.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Language::V1beta2::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.analyze_syntax.timeout, metadata: metadata, retry_policy: @config.rpcs.analyze_syntax.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @language_service_stub.call_rpc :analyze_syntax, request, options: options do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end
A convenience method that provides all syntax, sentiment, entity, and classification features in one call.
@overload annotate_text
(request, options = nil)
Pass arguments to `annotate_text` via a request object, either of type {::Google::Cloud::Language::V1beta2::AnnotateTextRequest} or an equivalent Hash. @param request [::Google::Cloud::Language::V1beta2::AnnotateTextRequest, ::Hash] A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload annotate_text
(document: nil, features: nil, encoding_type: nil)
Pass arguments to `annotate_text` via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above). @param document [::Google::Cloud::Language::V1beta2::Document, ::Hash] Required. Input document. @param features [::Google::Cloud::Language::V1beta2::AnnotateTextRequest::Features, ::Hash] Required. The enabled features. @param encoding_type [::Google::Cloud::Language::V1beta2::EncodingType] The encoding type used by the API to calculate offsets.
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Language::V1beta2::AnnotateTextResponse] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Google::Cloud::Language::V1beta2::AnnotateTextResponse]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/language/v1beta2/language_service/client.rb, line 534 def annotate_text request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V1beta2::AnnotateTextRequest # Converts hash and nil to an options object options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults metadata = @config.rpcs.annotate_text.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Language::V1beta2::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.annotate_text.timeout, metadata: metadata, retry_policy: @config.rpcs.annotate_text.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @language_service_stub.call_rpc :annotate_text, request, options: options do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end
Classifies a document into categories.
@overload classify_text
(request, options = nil)
Pass arguments to `classify_text` via a request object, either of type {::Google::Cloud::Language::V1beta2::ClassifyTextRequest} or an equivalent Hash. @param request [::Google::Cloud::Language::V1beta2::ClassifyTextRequest, ::Hash] A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload classify_text
(document: nil)
Pass arguments to `classify_text` via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above). @param document [::Google::Cloud::Language::V1beta2::Document, ::Hash] Required. Input document.
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Language::V1beta2::ClassifyTextResponse] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Google::Cloud::Language::V1beta2::ClassifyTextResponse]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/language/v1beta2/language_service/client.rb, line 467 def classify_text request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V1beta2::ClassifyTextRequest # Converts hash and nil to an options object options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults metadata = @config.rpcs.classify_text.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Language::V1beta2::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id options.apply_defaults timeout: @config.rpcs.classify_text.timeout, metadata: metadata, retry_policy: @config.rpcs.classify_text.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @language_service_stub.call_rpc :classify_text, request, options: options do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end
Configure the LanguageService
Client
instance.
The configuration is set to the derived mode, meaning that values can be changed, but structural changes (adding new fields, etc.) are not allowed. Structural changes should be made on {Client.configure}.
See {::Google::Cloud::Language::V1beta2::LanguageService::Client::Configuration} for a description of the configuration fields.
@yield [config] Configure the Client
client. @yieldparam config [Client::Configuration]
@return [Client::Configuration]
# File lib/google/cloud/language/v1beta2/language_service/client.rb, line 117 def configure yield @config if block_given? @config end