google-cloud-language 0.27.1 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,143 +0,0 @@
1
- # Copyright 2016 Google Inc. All rights reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
-
16
- require "google/cloud/errors"
17
- require "google/cloud/language/credentials"
18
- require "google/cloud/language/version"
19
- require "google/cloud/language/v1"
20
-
21
- module Google
22
- module Cloud
23
- module Language
24
- ##
25
- # @private Represents the gRPC Language service, including all the API
26
- # methods.
27
- class Service
28
- attr_accessor :project, :credentials, :host, :client_config, :timeout
29
-
30
- ##
31
- # Creates a new Service instance.
32
- def initialize project, credentials, host: nil, client_config: nil,
33
- timeout: nil
34
- @project = project
35
- @credentials = credentials
36
- @host = host || V1::LanguageServiceClient::SERVICE_ADDRESS
37
- @client_config = client_config || {}
38
- @timeout = timeout
39
- end
40
-
41
- def channel
42
- require "grpc"
43
- GRPC::Core::Channel.new host, nil, chan_creds
44
- end
45
-
46
- def chan_creds
47
- return credentials if insecure?
48
- require "grpc"
49
- GRPC::Core::ChannelCredentials.new.compose \
50
- GRPC::Core::CallCredentials.new credentials.client.updater_proc
51
- end
52
-
53
- def service
54
- return mocked_service if mocked_service
55
- @service ||= V1::LanguageServiceClient.new(
56
- service_path: host,
57
- channel: channel,
58
- timeout: timeout,
59
- client_config: client_config,
60
- lib_name: "gccl",
61
- lib_version: Google::Cloud::Language::VERSION)
62
- end
63
- attr_accessor :mocked_service
64
-
65
- def insecure?
66
- credentials == :this_channel_is_insecure
67
- end
68
-
69
- ##
70
- # Returns API::BatchAnnotateImagesResponse
71
- def annotate doc_grpc, syntax: false, entities: false, sentiment: false
72
- if syntax == false && entities == false && sentiment == false
73
- syntax = true
74
- entities = true
75
- sentiment = true
76
- end
77
- features = V1::AnnotateTextRequest::Features.new(
78
- extract_syntax: syntax, extract_entities: entities,
79
- extract_document_sentiment: sentiment)
80
- execute do
81
- service.annotate_text doc_grpc, features, default_encoding,
82
- options: default_options
83
- end
84
- end
85
-
86
- def syntax doc_grpc
87
- execute do
88
- service.analyze_syntax doc_grpc, default_encoding,
89
- options: default_options
90
- end
91
- end
92
-
93
- def entities doc_grpc
94
- execute do
95
- service.analyze_entities doc_grpc, default_encoding,
96
- options: default_options
97
- end
98
- end
99
-
100
- def sentiment doc_grpc
101
- execute do
102
- service.analyze_sentiment doc_grpc, encoding_type: default_encoding,
103
- options: default_options
104
- end
105
- end
106
-
107
- def inspect
108
- "#{self.class}(#{@project})"
109
- end
110
-
111
- protected
112
-
113
- def default_headers
114
- { "google-cloud-resource-prefix" => "projects/#{@project}" }
115
- end
116
-
117
- def default_options
118
- Google::Gax::CallOptions.new kwargs: default_headers
119
- end
120
-
121
- def default_encoding
122
- utf_16_encodings = [Encoding::UTF_16, Encoding::UTF_16BE,
123
- Encoding::UTF_16LE]
124
- return :UTF16 if utf_16_encodings.include? Encoding.default_internal
125
-
126
- utf_32_encodings = [Encoding::UTF_32, Encoding::UTF_32BE,
127
- Encoding::UTF_32LE]
128
- return :UTF32 if utf_32_encodings.include? Encoding.default_internal
129
-
130
- # The default encoding_type for all other system settings
131
- :UTF8
132
- end
133
-
134
- def execute
135
- yield
136
- rescue Google::Gax::GaxError => e
137
- # GaxError wraps BadStatus, but exposes it as #cause
138
- raise Google::Cloud::Error.from_error(e.cause)
139
- end
140
- end
141
- end
142
- end
143
- end
@@ -1,22 +0,0 @@
1
- # Copyright 2016 Google Inc. All rights reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
-
16
- module Google
17
- module Cloud
18
- module Language
19
- VERSION = "0.27.1"
20
- end
21
- end
22
- end