google-cloud-language 0.27.1 → 0.28.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 640b2b45f1a1c1591831ec87517594559da9089e
4
- data.tar.gz: 667181d885dd29cb5bf5638d9671b4e5070bfd75
2
+ SHA256:
3
+ metadata.gz: 577cf57a9adac4e45b66f535d28a678748bf9b4641ff2f7cc395af122d4c16bb
4
+ data.tar.gz: 12920a68328d2168090dac303fc7d5ac3a1a46fa79ba91c05111b19a330676ad
5
5
  SHA512:
6
- metadata.gz: e7466b754816e35ad9da93f510a7666073c5e4852310f4d9ee8b76700ebf51fa4be842eb868fce581fb7a55df349d81c25cddaec3ce12a92b10b4b37de3ce692
7
- data.tar.gz: a0dbb87e8d94baadbf8c7e9110775bbf11c007754aa73c49b8da878ba9461809d7ecaaf8be064806b0e8313156340ac1ba9b71d5b3197e1315cc66488acc66b9
6
+ metadata.gz: eb8130b0e8dc4cc3f5d9a9e0f43f57b403c673d1f60adc06600de84bbd6ddc7214673ae50f3ae8e5a6532669860661e355f8036233bd5e0e385c3c0cf03c5df5
7
+ data.tar.gz: df63b764ba60e4b7e84f89ba74bf0529918b8794a0ca5c69b339c1c7e2667cdb965b4e4a5f554cbb0f65148ab7947f04d51bffbd4c8a8bee1e93341241890a56
data/.yardopts CHANGED
@@ -1,10 +1,6 @@
1
1
  --no-private
2
- --title=Google Cloud Language
3
- --exclude lib/google/cloud/language/v1.rb
4
- --exclude lib/google/cloud/language/v1/language_service_pb.rb
5
- --exclude lib/google/cloud/language/v1/language_service_services_pb.rb
6
- --exclude lib/google/cloud/language/v1beta2/language_service_pb.rb
7
- --exclude lib/google/cloud/language/v1beta2/language_service_services_pb.rb
2
+ --title=Google Cloud Natural Language API
3
+ --exclude _pb\.rb$
8
4
  --markup markdown
9
5
 
10
6
  ./lib/**/*.rb
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Apache License
1
+ Apache License
2
2
  Version 2.0, January 2004
3
3
  http://www.apache.org/licenses/
4
4
 
data/README.md CHANGED
@@ -1,72 +1,48 @@
1
- # google-cloud-language
1
+ # Ruby Client for Google Cloud Natural Language API ([Beta](https://github.com/GoogleCloudPlatform/google-cloud-ruby#versioning))
2
2
 
3
- [Google Cloud Natural Language API](https://cloud.google.com/natural-language/) ([docs](https://cloud.google.com/natural-language/docs)) reveals the structure and meaning of text by offering powerful machine learning models in an easy to use REST API. You can use it to extract information about people, places, events and much more, mentioned in text documents, news articles or blog posts. You can use it to understand sentiment about your product on social media or parse intent from customer conversations happening in a call center or a messaging app. You can analyze text uploaded in your request or integrate with your document storage on Google Cloud Storage.
3
+ [Google Cloud Natural Language API][Product Documentation]:
4
+ Google Cloud Natural Language API provides natural language understanding
5
+ technologies to developers. Examples include sentiment analysis, entity
6
+ recognition, and text annotations.
7
+ - [Client Library Documentation][]
8
+ - [Product Documentation][]
4
9
 
5
- The Cloud Natural Language API currently supports English, Spanish, and Japanese for sentiment analysis, entity analysis, and syntax analysis.
6
-
7
- - [google-cloud-language API documentation](http://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-language/latest)
8
- - [google-cloud-language on RubyGems](https://rubygems.org/gems/google-cloud-language)
9
- - [Google Cloud Natural Language API documentation](https://cloud.google.com/natural-language/docs)
10
+ *This release, 0.28.0, introduces breaking changes relative to the previous
11
+ release, 0.27.1. For more details and instructions to migrate your code, please
12
+ visit the [migration guide](https://cloud.google.com/natural-language/docs/ruby-client-migration).*
10
13
 
11
14
  ## Quick Start
15
+ In order to use this library, you first need to go through the following
16
+ steps:
17
+
18
+ 1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project)
19
+ 2. [Enable the Google Cloud Natural Language API.](https://console.cloud.google.com/apis/api/language)
20
+ 3. [Setup Authentication.](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud/master/guides/authentication)
12
21
 
13
- ```sh
22
+ ### Installation
23
+ ```
14
24
  $ gem install google-cloud-language
15
25
  ```
16
26
 
17
- ## Authentication
18
-
19
- This library uses Service Account credentials to connect to Google Cloud services. When running on Compute Engine the credentials will be discovered automatically. When running on other environments the Service Account credentials can be specified by providing the path to the JSON file, or the JSON itself, in environment variables.
20
-
21
- Instructions and configuration options are covered in the [Authentication Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-language/guides/authentication).
22
-
23
- ## Example
24
-
25
- ```ruby
27
+ ### Preview
28
+ #### LanguageServiceClient
29
+ ```rb
26
30
  require "google/cloud/language"
27
31
 
28
- language = Google::Cloud::Language.new
29
-
30
- content = "Star Wars is a great movie. The Death Star is fearsome."
31
- document = language.document content
32
- annotation = document.annotate
33
-
34
- annotation.entities.count #=> 3
35
- annotation.sentiment.score #=> 0.10000000149011612
36
- annotation.sentiment.magnitude #=> 1.100000023841858
37
- annotation.sentences.count #=> 2
38
- annotation.tokens.count #=> 13
32
+ language_service_client = Google::Cloud::Language.new
33
+ content = "Hello, world!"
34
+ type = :PLAIN_TEXT
35
+ document = { content: content, type: type }
36
+ response = language_service_client.analyze_sentiment(document)
39
37
  ```
40
38
 
41
- ## Supported Ruby Versions
42
-
43
- This library is supported on Ruby 2.0+.
44
-
45
- ## Versioning
46
-
47
- This library follows [Semantic Versioning](http://semver.org/).
48
-
49
- It is currently in major version zero (0.y.z), which means that anything may change at any time and the public API should not be considered stable.
50
-
51
- ### Lower-level (GAPIC) API versioning
52
-
53
- The lower-level API support contained within this package is versioned separately to match its corresponding Google Cloud Platform service API version.
54
-
55
- *Please note that in lower-level API support in this package, version `v1beta2` comes after version `v1`. The API version `v1beta2` contains new features that were not released in `v1`.*
56
-
57
- ## Contributing
58
-
59
- Contributions to this library are always welcome and highly encouraged.
60
-
61
- See the [Contributing Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/contributing) for more information on how to get started.
62
-
63
- Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct](../CODE_OF_CONDUCT.md) for more information.
64
-
65
- ## License
66
-
67
- This library is licensed under Apache 2.0. Full license text is available in [LICENSE](LICENSE).
68
-
69
- ## Support
39
+ ### Next Steps
40
+ - Read the [Client Library Documentation][] for Google Cloud Natural Language API
41
+ to see other available methods on the client.
42
+ - Read the [Google Cloud Natural Language API Product documentation][Product Documentation]
43
+ to learn more about the product and see How-to Guides.
44
+ - View this [repository's main README](https://github.com/GoogleCloudPlatform/google-cloud-ruby/blob/master/README.md)
45
+ to see the full list of Cloud APIs that we cover.
70
46
 
71
- Please [report bugs at the project on Github](https://github.com/GoogleCloudPlatform/google-cloud-ruby/issues).
72
- Don't hesitate to [ask questions](http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby) about the client or APIs on [StackOverflow](http://stackoverflow.com).
47
+ [Client Library Documentation]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-language/latest/google/cloud/language/v1
48
+ [Product Documentation]: https://cloud.google.com/language
@@ -1,4 +1,4 @@
1
- # Copyright 2016 Google Inc. All rights reserved.
1
+ # Copyright 2017, Google Inc. All rights reserved.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -12,255 +12,106 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
-
16
- require "google-cloud-language"
17
- require "google/cloud/language/project"
15
+ require "google/gax"
16
+ require "pathname"
18
17
 
19
18
  module Google
20
19
  module Cloud
20
+ # rubocop:disable LineLength
21
+
21
22
  ##
22
- # # Google Cloud Natural Language API
23
- #
24
- # Google Cloud Natural Language API reveals the structure and meaning of
25
- # text by offering powerful machine learning models in an easy to use REST
26
- # API. You can use it to extract information about people, places, events
27
- # and much more, mentioned in text documents, news articles or blog posts.
28
- # You can use it to understand sentiment about your product on social media
29
- # or parse intent from customer conversations happening in a call center or
30
- # a messaging app. You can analyze text uploaded in your request or
31
- # integrate with your document storage on Google Cloud Storage. Combine the
32
- # API with the Google Cloud Speech API and extract insights from audio
33
- # conversations. Use with Vision API OCR to understand scanned documents.
34
- # Extract entities and understand sentiments in multiple languages by
35
- # translating text first with Cloud Translation API.
36
- #
37
- # For more information about Cloud Natural Language API, read the [Google
38
- # Cloud Natural Language API
39
- # Documentation](https://cloud.google.com/natural-language/docs/).
40
- #
41
- # The goal of google-cloud is to provide an API that is comfortable to
42
- # Rubyists. Authentication is handled by {Google::Cloud#language}. You can
43
- # provide the project and credential information to connect to the Cloud
44
- # Natural Language API, or if you are running on Google Compute Engine this
45
- # configuration is taken care of for you. You can read more about the
46
- # options for connecting in the [Authentication
47
- # Guide](https://googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).
48
- #
49
- # ## Creating documents
50
- #
51
- # Use {Language::Project#document} to create documents for the Cloud Natural
52
- # Language service. (The Cloud Natural Language API currently supports
53
- # English, Spanish, and Japanese.)
54
- #
55
- # You can provide text or HTML content as a string:
56
- #
57
- # ```ruby
58
- # require "google/cloud/language"
59
- #
60
- # language = Google::Cloud::Language.new
61
- #
62
- # document = language.document "It was the best of times, it was..."
63
- # ```
64
- #
65
- # Or, you can pass a Google Cloud Storage URI for a text or HTML file:
66
- #
67
- # ```ruby
68
- # require "google/cloud/language"
69
- #
70
- # language = Google::Cloud::Language.new
71
- #
72
- # document = language.document "gs://bucket-name/path/to/document"
73
- # ```
74
- #
75
- # Or, you can initialize it with a Google Cloud Storage File object:
76
- #
77
- # ```ruby
78
- # require "google/cloud/storage"
79
- #
80
- # storage = Google::Cloud::Storage.new
81
- #
82
- # bucket = storage.bucket "bucket-name"
83
- # file = bucket.file "path/to/document"
84
- #
85
- # require "google/cloud/language"
86
- #
87
- # language = Google::Cloud::Language.new
88
- #
89
- # document = language.document file
90
- # ```
91
- #
92
- # You can specify the format and language of the content:
93
- #
94
- # ```ruby
95
- # require "google/cloud/language"
96
- #
97
- # language = Google::Cloud::Language.new
98
- #
99
- # document = language.document "<p>El viejo y el mar</p>",
100
- # format: :html, language: "es"
101
- # ```
102
- #
103
- # Creating a Document instance does not perform an API request.
104
- #
105
- # ## Annotating documents
106
- #
107
- # The instance methods on {Language::Document} invoke Cloud Natural
108
- # Language's detection features individually. Each method call makes an API
109
- # request. If you want to run multiple features in a single request, see
110
- # the examples for {Language::Document#annotate}, below. Calling `annotate`
111
- # with no arguments will perform **all** analysis features. Each feature
112
- # is priced separately. See [Pricing](https://cloud.google.com/natural-language/pricing)
113
- # for details.
23
+ # # Ruby Client for Google Cloud Natural Language API ([Alpha](https://github.com/GoogleCloudPlatform/google-cloud-ruby#versioning))
114
24
  #
115
- # Sentiment analysis inspects the given text and identifies the prevailing
116
- # emotional opinion within the text, especially to determine a writer's
117
- # attitude as positive, negative, or neutral. Sentiment analysis can be
118
- # performed with the {Language::Document#sentiment} method. Currently, only
119
- # English is supported for sentiment analysis.
25
+ # [Google Cloud Natural Language API][Product Documentation]:
26
+ # Google Cloud Natural Language API provides natural language understanding
27
+ # technologies to developers. Examples include sentiment analysis, entity
28
+ # recognition, and text annotations.
29
+ # - [Product Documentation][]
120
30
  #
121
- # ```ruby
122
- # require "google/cloud/language"
123
- #
124
- # language = Google::Cloud::Language.new
125
- #
126
- # content = "Star Wars is a great movie. The Death Star is fearsome."
127
- # document = language.document content
128
- # sentiment = document.sentiment # API call
129
- #
130
- # sentiment.score #=> 0.10000000149011612
131
- # sentiment.magnitude #=> 1.100000023841858
132
- # ```
31
+ # ## Quick Start
32
+ # In order to use this library, you first need to go through the following
33
+ # steps:
133
34
  #
134
- # Entity analysis inspects the given text for known entities (proper nouns
135
- # such as public figures, landmarks, etc.) and returns information about
136
- # those entities. Entity analysis can be performed with the
137
- # {Language::Document#entities} method.
35
+ # 1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project)
36
+ # 2. [Enable the Google Cloud Natural Language API.](https://console.cloud.google.com/apis/api/language)
37
+ # 3. [Setup Authentication.](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud/master/guides/authentication)
138
38
  #
139
- # ```ruby
39
+ # ### Preview
40
+ # #### LanguageServiceClient
41
+ # ```rb
140
42
  # require "google/cloud/language"
141
43
  #
142
- # language = Google::Cloud::Language.new
143
- #
144
- # content = "Star Wars is a great movie. The Death Star is fearsome."
145
- # document = language.document content
146
- # entities = document.entities # API call
147
- #
148
- # entities.count #=> 3
149
- # entities.first.name #=> "Star Wars"
150
- # entities.first.type #=> :WORK_OF_ART
151
- # entities.first.mid #=> "/m/06mmr"
152
- # entities.first.wikipedia_url #=> "http://en.wikipedia.org/wiki/Star_Wars"
44
+ # language_service_client = Google::Cloud::Language.new
45
+ # content = "Hello, world!"
46
+ # type = :PLAIN_TEXT
47
+ # document = { content: content, type: type }
48
+ # response = language_service_client.analyze_sentiment(document)
153
49
  # ```
154
50
  #
155
- # Syntactic analysis extracts linguistic information, breaking up the given
156
- # text into a series of sentences and tokens (generally, word boundaries),
157
- # providing further analysis on those tokens. Syntactic analysis can be
158
- # performed with the {Language::Document#syntax} method.
159
- #
160
- # ```ruby
161
- # require "google/cloud/language"
162
- #
163
- # language = Google::Cloud::Language.new
51
+ # ### Next Steps
52
+ # - Read the [Google Cloud Natural Language API Product documentation][Product Documentation]
53
+ # to learn more about the product and see How-to Guides.
54
+ # - View this [repository's main README](https://github.com/GoogleCloudPlatform/google-cloud-ruby/blob/master/README.md)
55
+ # to see the full list of Cloud APIs that we cover.
164
56
  #
165
- # content = "Star Wars is a great movie. The Death Star is fearsome."
166
- # document = language.document content
167
- # syntax = document.syntax # API call
168
- #
169
- # syntax.sentences.count #=> 2
170
- # syntax.tokens.count #=> 13
171
- # ```
172
- #
173
- # To run multiple features on a document in a single request, pass the flag
174
- # for each desired feature to {Language::Document#annotate}:
175
- #
176
- # ```ruby
177
- # require "google/cloud/language"
178
- #
179
- # language = Google::Cloud::Language.new
180
- #
181
- # content = "Star Wars is a great movie. The Death Star is fearsome."
182
- # document = language.document content
183
- # annotation = document.annotate entities: true, syntax: true
184
- #
185
- # annotation.entities.count #=> 3
186
- # annotation.sentences.count #=> 2
187
- # annotation.tokens.count #=> 13
188
- # ```
57
+ # [Product Documentation]: https://cloud.google.com/language
189
58
  #
190
- # Or, simply call {Language::Document#annotate} with no arguments to process
191
- # the document with **all** features:
192
- #
193
- # ```ruby
194
- # require "google/cloud/language"
195
- #
196
- # language = Google::Cloud::Language.new
197
- #
198
- # content = "Star Wars is a great movie. The Death Star is fearsome."
199
- # document = language.document content
200
- # annotation = document.annotate
201
- #
202
- # annotation.sentiment.score #=> 0.10000000149011612
203
- # annotation.sentiment.magnitude #=> 1.100000023841858
204
- # annotation.entities.count #=> 3
205
- # annotation.sentences.count #=> 2
206
- # annotation.tokens.count #=> 13
207
- # ```
208
59
  #
209
60
  module Language
61
+ # rubocop:enable LineLength
62
+
63
+ FILE_DIR = File.realdirpath(Pathname.new(__FILE__).join("..").join("language"))
64
+
65
+ AVAILABLE_VERSIONS = Dir["#{FILE_DIR}/*"]
66
+ .select { |file| File.directory?(file) }
67
+ .select { |dir| Google::Gax::VERSION_MATCHER.match(File.basename(dir)) }
68
+ .select { |dir| File.exist?(dir + ".rb") }
69
+ .map { |dir| File.basename(dir) }
70
+
210
71
  ##
211
- # Creates a new object for connecting to the Language service.
212
- # Each call creates a new connection.
72
+ # Provides text analysis operations such as sentiment analysis and entity
73
+ # recognition.
213
74
  #
214
- # For more information on connecting to Google Cloud see the
215
- # [Authentication
216
- # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
217
- #
218
- # @param [String] project Project identifier for the Language service you
219
- # are connecting to.
220
- # @param [String, Hash] keyfile Keyfile downloaded from Google Cloud. If
221
- # file path the file must be readable.
222
- # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling
223
- # the set of resources and operations that the connection can access.
224
- # See [Using OAuth 2.0 to Access Google
225
- # APIs](https://developers.goorequire
226
- # "google/cloud"gle.com/identity/protocols/OAuth2).
227
- #
228
- # The default scope is:
229
- #
230
- # * `"https://www.googleapis.com/auth/cloud-platform"`
231
- # @param [Integer] timeout Default timeout to use in requests. Optional.
232
- # @param [Hash] client_config A hash of values to override the default
233
- # behavior of the API client. Optional.
234
- #
235
- # @return [Google::Cloud::Language::Project]
236
- #
237
- # @example
238
- # require "google/cloud/language"
239
- #
240
- # language = Google::Cloud::Language.new
241
- #
242
- # content = "Star Wars is a great movie. The Death Star is fearsome."
243
- # document = language.document content
244
- # annotation = document.annotate
245
- #
246
- def self.new project: nil, keyfile: nil, scope: nil, timeout: nil,
247
- client_config: nil
248
- project ||= Google::Cloud::Language::Project.default_project
249
- project = project.to_s # Always cast to a string
250
- fail ArgumentError, "project is missing" if project.empty?
251
-
252
- if keyfile.nil?
253
- credentials = Google::Cloud::Language::Credentials.default(
254
- scope: scope)
255
- else
256
- credentials = Google::Cloud::Language::Credentials.new(
257
- keyfile, scope: scope)
75
+ # @param version [Symbol, String]
76
+ # The major version of the service to be used. By default :v1
77
+ # is used.
78
+ # @overload new(version:, credentials:, scopes:, client_config:, timeout:)
79
+ # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
80
+ # Provides the means for authenticating requests made by the client. This parameter can
81
+ # be many types.
82
+ # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
83
+ # authenticating requests made by this client.
84
+ # A `String` will be treated as the path to the keyfile to be used for the construction of
85
+ # credentials for this client.
86
+ # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
87
+ # credentials for this client.
88
+ # A `GRPC::Core::Channel` will be used to make calls through.
89
+ # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
90
+ # should already be composed with a `GRPC::Core::CallCredentials` object.
91
+ # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
92
+ # metadata for requests, generally, to give OAuth credentials.
93
+ # @param scopes [Array<String>]
94
+ # The OAuth scopes for this service. This parameter is ignored if
95
+ # an updater_proc is supplied.
96
+ # @param client_config [Hash]
97
+ # A Hash for call options for each method. See
98
+ # Google::Gax#construct_settings for the structure of
99
+ # this data. Falls back to the default config if not specified
100
+ # or the specified config is missing data points.
101
+ # @param timeout [Numeric]
102
+ # The default timeout, in seconds, for calls made through this client.
103
+ def self.new(*args, version: :v1, **kwargs)
104
+ unless AVAILABLE_VERSIONS.include?(version.to_s.downcase)
105
+ raise "The version: #{version} is not available. The available versions " \
106
+ "are: [#{AVAILABLE_VERSIONS.join(", ")}]"
258
107
  end
259
108
 
260
- Google::Cloud::Language::Project.new(
261
- Google::Cloud::Language::Service.new(
262
- project, credentials, timeout: timeout,
263
- client_config: client_config))
109
+ require "#{FILE_DIR}/#{version.to_s.downcase}"
110
+ version_module = Google::Cloud::Language
111
+ .constants
112
+ .select {|sym| sym.to_s.downcase == version.to_s.downcase}
113
+ .first
114
+ Google::Cloud::Language.const_get(version_module).new(*args, **kwargs)
264
115
  end
265
116
  end
266
117
  end