Class: Google::Cloud::Language::Service
- Inherits:
-
Object
- Object
- Google::Cloud::Language::Service
- Defined in:
- lib/google/cloud/language/service.rb
Overview
methods.
Instance Attribute Summary collapse
-
#credentials ⇒ Object
Returns the value of attribute credentials.
-
#host ⇒ Object
Returns the value of attribute host.
-
#mocked_service ⇒ Object
Returns the value of attribute mocked_service.
-
#project ⇒ Object
Returns the value of attribute project.
-
#retries ⇒ Object
Returns the value of attribute retries.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#annotate(doc_grpc, syntax: false, entities: false, sentiment: false, encoding: nil) ⇒ Object
Returns API::BatchAnnotateImagesResponse.
- #chan_creds ⇒ Object
- #channel ⇒ Object
- #entities(doc_grpc, encoding: nil) ⇒ Object
-
#initialize(project, credentials, host: nil, retries: nil, timeout: nil) ⇒ Service
constructor
Creates a new Service instance.
- #insecure? ⇒ Boolean
- #inspect ⇒ Object
- #sentiment(doc_grpc) ⇒ Object
- #service ⇒ Object
Constructor Details
#initialize(project, credentials, host: nil, retries: nil, timeout: nil) ⇒ Service
Creates a new Service instance.
32 33 34 35 36 37 38 39 |
# File 'lib/google/cloud/language/service.rb', line 32 def initialize project, credentials, host: nil, retries: nil, timeout: nil @project = project @credentials = credentials @host = host || V1beta1::LanguageServiceApi::SERVICE_ADDRESS @retries = retries @timeout = timeout end |
Instance Attribute Details
#credentials ⇒ Object
Returns the value of attribute credentials.
28 29 30 |
# File 'lib/google/cloud/language/service.rb', line 28 def credentials @credentials end |
#host ⇒ Object
Returns the value of attribute host.
28 29 30 |
# File 'lib/google/cloud/language/service.rb', line 28 def host @host end |
#mocked_service ⇒ Object
Returns the value of attribute mocked_service.
65 66 67 |
# File 'lib/google/cloud/language/service.rb', line 65 def mocked_service @mocked_service end |
#project ⇒ Object
Returns the value of attribute project.
28 29 30 |
# File 'lib/google/cloud/language/service.rb', line 28 def project @project end |
#retries ⇒ Object
Returns the value of attribute retries.
28 29 30 |
# File 'lib/google/cloud/language/service.rb', line 28 def retries @retries end |
#timeout ⇒ Object
Returns the value of attribute timeout.
28 29 30 |
# File 'lib/google/cloud/language/service.rb', line 28 def timeout @timeout end |
Instance Method Details
#annotate(doc_grpc, syntax: false, entities: false, sentiment: false, encoding: nil) ⇒ Object
Returns API::BatchAnnotateImagesResponse
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/google/cloud/language/service.rb', line 73 def annotate doc_grpc, syntax: false, entities: false, sentiment: false, encoding: nil if syntax == false && entities == false && sentiment == false syntax = true entities = true sentiment = true end features = V1beta1::AnnotateTextRequest::Features.new( extract_syntax: syntax, extract_entities: entities, extract_document_sentiment: sentiment) encoding = verify_encoding! encoding execute { service.annotate_text doc_grpc, features, encoding } end |
#chan_creds ⇒ Object
45 46 47 48 49 |
# File 'lib/google/cloud/language/service.rb', line 45 def chan_creds return credentials if insecure? GRPC::Core::ChannelCredentials.new.compose \ GRPC::Core::CallCredentials.new credentials.client.updater_proc end |
#channel ⇒ Object
41 42 43 |
# File 'lib/google/cloud/language/service.rb', line 41 def channel GRPC::Core::Channel.new host, nil, chan_creds end |
#entities(doc_grpc, encoding: nil) ⇒ Object
87 88 89 90 |
# File 'lib/google/cloud/language/service.rb', line 87 def entities doc_grpc, encoding: nil encoding = verify_encoding! encoding execute { service.analyze_entities doc_grpc, encoding } end |
#insecure? ⇒ Boolean
67 68 69 |
# File 'lib/google/cloud/language/service.rb', line 67 def insecure? credentials == :this_channel_is_insecure end |
#inspect ⇒ Object
96 97 98 |
# File 'lib/google/cloud/language/service.rb', line 96 def inspect "#{self.class}(#{@project})" end |
#sentiment(doc_grpc) ⇒ Object
92 93 94 |
# File 'lib/google/cloud/language/service.rb', line 92 def sentiment doc_grpc execute { service.analyze_sentiment doc_grpc } end |
#service ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/google/cloud/language/service.rb', line 51 def service return mocked_service if mocked_service @service ||= begin require "google/cloud/language/v1beta1/language_service_api" V1beta1::LanguageServiceApi.new( service_path: host, channel: channel, timeout: timeout, app_name: "google-cloud-language", app_version: Google::Cloud::Language::VERSION) # TODO: Get retries configured end end |