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,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,20 +12,18 @@
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/credentials"
17
- require "google/cloud/language/v1"
15
+ require "googleauth"
18
16
 
19
17
  module Google
20
18
  module Cloud
21
19
  module Language
22
- ##
23
- # @private Represents the OAuth 2.0 signing logic for Language.
24
- class Credentials < Google::Cloud::Credentials
25
- SCOPE = V1::LanguageServiceClient::ALL_SCOPES
26
- PATH_ENV_VARS = %w(LANGUAGE_KEYFILE GOOGLE_CLOUD_KEYFILE GCLOUD_KEYFILE)
27
- JSON_ENV_VARS = %w(LANGUAGE_KEYFILE_JSON GOOGLE_CLOUD_KEYFILE_JSON
28
- GCLOUD_KEYFILE_JSON)
20
+ class Credentials < Google::Auth::Credentials
21
+ SCOPE = [
22
+ "https://www.googleapis.com/auth/cloud-platform"
23
+ ].freeze
24
+ PATH_ENV_VARS = %w(LANGUAGE_KEYFILE, GOOGLE_CLOUD_KEYFILE, GCLOUD_KEYFILE)
25
+ JSON_ENV_VARS = %w(LANGUAGE_KEYFILE_JSON, GOOGLE_CLOUD_KEYFILE_JSON, GCLOUD_KEYFILE_JSON)
26
+ DEFAULT_PATHS = ["~/.config/gcloud/application_default_credentials.json"]
29
27
  end
30
28
  end
31
29
  end
@@ -1,4 +1,5 @@
1
1
  # Copyright 2017, Google Inc. All rights reserved.
2
+ #
2
3
  # Licensed under the Apache License, Version 2.0 (the "License");
3
4
  # you may not use this file except in compliance with the License.
4
5
  # You may obtain a copy of the License at
@@ -12,3 +13,109 @@
12
13
  # limitations under the License.
13
14
 
14
15
  require "google/cloud/language/v1/language_service_client"
16
+
17
+ module Google
18
+ module Cloud
19
+ # rubocop:disable LineLength
20
+
21
+ ##
22
+ # # Ruby Client for Google Cloud Natural Language API ([Alpha](https://github.com/GoogleCloudPlatform/google-cloud-ruby#versioning))
23
+ #
24
+ # [Google Cloud Natural Language API][Product Documentation]:
25
+ # Google Cloud Natural Language API provides natural language understanding
26
+ # technologies to developers. Examples include sentiment analysis, entity
27
+ # recognition, and text annotations.
28
+ # - [Product Documentation][]
29
+ #
30
+ # ## Quick Start
31
+ # In order to use this library, you first need to go through the following
32
+ # steps:
33
+ #
34
+ # 1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project)
35
+ # 2. [Enable the Google Cloud Natural Language API.](https://console.cloud.google.com/apis/api/language)
36
+ # 3. [Setup Authentication.](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud/master/guides/authentication)
37
+ #
38
+ # ### Preview
39
+ # #### LanguageServiceClient
40
+ # ```rb
41
+ # require "google/cloud/language/v1"
42
+ #
43
+ # language_service_client = Google::Cloud::Language::V1.new
44
+ # content = "Hello, world!"
45
+ # type = :PLAIN_TEXT
46
+ # document = { content: content, type: type }
47
+ # response = language_service_client.analyze_sentiment(document)
48
+ # ```
49
+ #
50
+ # ### Next Steps
51
+ # - Read the [Google Cloud Natural Language API Product documentation][Product Documentation]
52
+ # to learn more about the product and see How-to Guides.
53
+ # - View this [repository's main README](https://github.com/GoogleCloudPlatform/google-cloud-ruby/blob/master/README.md)
54
+ # to see the full list of Cloud APIs that we cover.
55
+ #
56
+ # [Product Documentation]: https://cloud.google.com/language
57
+ #
58
+ #
59
+ module Language
60
+ module V1
61
+ # rubocop:enable LineLength
62
+
63
+ ##
64
+ # Provides text analysis operations such as sentiment analysis and entity
65
+ # recognition.
66
+ #
67
+ # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
68
+ # Provides the means for authenticating requests made by the client. This parameter can
69
+ # be many types.
70
+ # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
71
+ # authenticating requests made by this client.
72
+ # A `String` will be treated as the path to the keyfile to be used for the construction of
73
+ # credentials for this client.
74
+ # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
75
+ # credentials for this client.
76
+ # A `GRPC::Core::Channel` will be used to make calls through.
77
+ # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
78
+ # should already be composed with a `GRPC::Core::CallCredentials` object.
79
+ # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
80
+ # metadata for requests, generally, to give OAuth credentials.
81
+ # @param scopes [Array<String>]
82
+ # The OAuth scopes for this service. This parameter is ignored if
83
+ # an updater_proc is supplied.
84
+ # @param client_config [Hash]
85
+ # A Hash for call options for each method. See
86
+ # Google::Gax#construct_settings for the structure of
87
+ # this data. Falls back to the default config if not specified
88
+ # or the specified config is missing data points.
89
+ # @param timeout [Numeric]
90
+ # The default timeout, in seconds, for calls made through this client.
91
+ def self.new \
92
+ service_path: nil,
93
+ port: nil,
94
+ channel: nil,
95
+ chan_creds: nil,
96
+ updater_proc: nil,
97
+ credentials: nil,
98
+ scopes: nil,
99
+ client_config: nil,
100
+ timeout: nil,
101
+ lib_name: nil,
102
+ lib_version: nil
103
+ kwargs = {
104
+ service_path: service_path,
105
+ port: port,
106
+ channel: channel,
107
+ chan_creds: chan_creds,
108
+ updater_proc: updater_proc,
109
+ credentials: credentials,
110
+ scopes: scopes,
111
+ client_config: client_config,
112
+ timeout: timeout,
113
+ lib_name: lib_name,
114
+ lib_version: lib_version
115
+ }.select { |_, v| v != nil }
116
+ Google::Cloud::Language::V1::LanguageServiceClient.new(**kwargs)
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
@@ -1,4 +1,4 @@
1
- # Copyright 2017, Google Inc. All rights reserved.
1
+ # Copyright 2017, Google LLC 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.
@@ -15,6 +15,17 @@
15
15
  module Google
16
16
  module Cloud
17
17
  module Language
18
+ ##
19
+ # # Google Cloud Natural Language API Contents
20
+ #
21
+ # | Class | Description |
22
+ # | ----- | ----------- |
23
+ # | [LanguageServiceClient][] | Google Cloud Natural Language API provides natural language understanding technologies to developers. Examples include sentiment analysis, entity recognition, and text annotations. |
24
+ # | [Data Types][] | Data types for Google::Cloud::Language::V1 |
25
+ #
26
+ # [LanguageServiceClient]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-language/latest/google/cloud/language/v1/languageserviceclient
27
+ # [Data Types]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-language/latest/google/cloud/language/v1/datatypes
28
+ #
18
29
  module V1
19
30
  # ================================================================ #
20
31
  #
@@ -37,9 +48,8 @@ module Google
37
48
  # The language of the document (if not specified, the language is
38
49
  # automatically detected). Both ISO and BCP-47 language codes are
39
50
  # accepted.<br>
40
- # **Current Language Restrictions:**
41
- #
42
- # * Only English, Spanish, and Japanese textual content are supported.
51
+ # [Language Support](https://cloud.google.com/natural-language/docs/languages)
52
+ # lists currently supported languages for each API method.
43
53
  # If the language (either specified by the caller or automatically detected)
44
54
  # is not supported by the called API method, an +INVALID_ARGUMENT+ error
45
55
  # is returned.
@@ -63,8 +73,8 @@ module Google
63
73
  # The sentence text.
64
74
  # @!attribute [rw] sentiment
65
75
  # @return [Google::Cloud::Language::V1::Sentiment]
66
- # For calls to AnalyzeSentiment or if
67
- # AnnotateTextRequest::Features#extract_document_sentiment is set to
76
+ # For calls to {AnalyzeSentiment} or if
77
+ # {Google::Cloud::Language::V1::AnnotateTextRequest::Features#extract_document_sentiment AnnotateTextRequest::Features#extract_document_sentiment} is set to
68
78
  # true, this field will contain the sentiment for the sentence.
69
79
  class Sentence; end
70
80
 
@@ -95,6 +105,12 @@ module Google
95
105
  # @return [Array<Google::Cloud::Language::V1::EntityMention>]
96
106
  # The mentions of this entity in the input document. The API currently
97
107
  # supports proper noun mentions.
108
+ # @!attribute [rw] sentiment
109
+ # @return [Google::Cloud::Language::V1::Sentiment]
110
+ # For calls to {AnalyzeEntitySentiment} or if
111
+ # {Google::Cloud::Language::V1::AnnotateTextRequest::Features#extract_entity_sentiment AnnotateTextRequest::Features#extract_entity_sentiment} is set to
112
+ # true, this field will contain the aggregate sentiment expressed for this
113
+ # entity in the provided document.
98
114
  class Entity
99
115
  # The type of the entity.
100
116
  module Type
@@ -136,7 +152,7 @@ module Google
136
152
  # Dependency tree parse for this token.
137
153
  # @!attribute [rw] lemma
138
154
  # @return [String]
139
- # {Lemma}[https://en.wikipedia.org/wiki/Lemma_%28morphology%29] of the token.
155
+ # [Lemma](https://en.wikipedia.org/wiki/Lemma_%28morphology%29) of the token.
140
156
  class Token; end
141
157
 
142
158
  # Represents the feeling associated with the entire text or entities in
@@ -728,6 +744,24 @@ module Google
728
744
 
729
745
  # Dislocated relation (for fronted/topicalized elements)
730
746
  DISLOCATED = 76
747
+
748
+ # Aspect marker
749
+ ASP = 77
750
+
751
+ # Genitive modifier
752
+ GMOD = 78
753
+
754
+ # Genitive object
755
+ GOBJ = 79
756
+
757
+ # Infinitival modifier
758
+ INFMOD = 80
759
+
760
+ # Measure
761
+ MES = 81
762
+
763
+ # Nominal complement of a noun
764
+ NCOMP = 82
731
765
  end
732
766
  end
733
767
 
@@ -739,6 +773,12 @@ module Google
739
773
  # @!attribute [rw] type
740
774
  # @return [Google::Cloud::Language::V1::EntityMention::Type]
741
775
  # The type of the entity mention.
776
+ # @!attribute [rw] sentiment
777
+ # @return [Google::Cloud::Language::V1::Sentiment]
778
+ # For calls to {AnalyzeEntitySentiment} or if
779
+ # {Google::Cloud::Language::V1::AnnotateTextRequest::Features#extract_entity_sentiment AnnotateTextRequest::Features#extract_entity_sentiment} is set to
780
+ # true, this field will contain the sentiment expressed for this mention of
781
+ # the entity in the provided document.
742
782
  class EntityMention
743
783
  # The supported types of mentions.
744
784
  module Type
@@ -760,14 +800,23 @@ module Google
760
800
  # @!attribute [rw] begin_offset
761
801
  # @return [Integer]
762
802
  # The API calculates the beginning offset of the content in the original
763
- # document according to the EncodingType specified in the API request.
803
+ # document according to the {Google::Cloud::Language::V1::EncodingType EncodingType} specified in the API request.
764
804
  class TextSpan; end
765
805
 
806
+ # Represents a category returned from the text classifier.
807
+ # @!attribute [rw] name
808
+ # @return [String]
809
+ # The name of the category representing the document.
810
+ # @!attribute [rw] confidence
811
+ # @return [Float]
812
+ # The classifier's confidence of the category. Number represents how certain
813
+ # the classifier is that this category represents the given text.
814
+ class ClassificationCategory; end
815
+
766
816
  # The sentiment analysis request message.
767
817
  # @!attribute [rw] document
768
818
  # @return [Google::Cloud::Language::V1::Document]
769
- # Input document. Currently, +analyzeSentiment+ only supports English text
770
- # (Document#language="EN").
819
+ # Input document.
771
820
  # @!attribute [rw] encoding_type
772
821
  # @return [Google::Cloud::Language::V1::EncodingType]
773
822
  # The encoding type used by the API to calculate sentence offsets.
@@ -781,12 +830,32 @@ module Google
781
830
  # @return [String]
782
831
  # The language of the text, which will be the same as the language specified
783
832
  # in the request or, if not specified, the automatically-detected language.
784
- # See +Document.language+ field for more details.
833
+ # See {Google::Cloud::Language::V1::Document#language Document#language} field for more details.
785
834
  # @!attribute [rw] sentences
786
835
  # @return [Array<Google::Cloud::Language::V1::Sentence>]
787
836
  # The sentiment for all the sentences in the document.
788
837
  class AnalyzeSentimentResponse; end
789
838
 
839
+ # The entity-level sentiment analysis request message.
840
+ # @!attribute [rw] document
841
+ # @return [Google::Cloud::Language::V1::Document]
842
+ # Input document.
843
+ # @!attribute [rw] encoding_type
844
+ # @return [Google::Cloud::Language::V1::EncodingType]
845
+ # The encoding type used by the API to calculate offsets.
846
+ class AnalyzeEntitySentimentRequest; end
847
+
848
+ # The entity-level sentiment analysis response message.
849
+ # @!attribute [rw] entities
850
+ # @return [Array<Google::Cloud::Language::V1::Entity>]
851
+ # The recognized entities in the input document with associated sentiments.
852
+ # @!attribute [rw] language
853
+ # @return [String]
854
+ # The language of the text, which will be the same as the language specified
855
+ # in the request or, if not specified, the automatically-detected language.
856
+ # See {Google::Cloud::Language::V1::Document#language Document#language} field for more details.
857
+ class AnalyzeEntitySentimentResponse; end
858
+
790
859
  # The entity analysis request message.
791
860
  # @!attribute [rw] document
792
861
  # @return [Google::Cloud::Language::V1::Document]
@@ -804,7 +873,7 @@ module Google
804
873
  # @return [String]
805
874
  # The language of the text, which will be the same as the language specified
806
875
  # in the request or, if not specified, the automatically-detected language.
807
- # See +Document.language+ field for more details.
876
+ # See {Google::Cloud::Language::V1::Document#language Document#language} field for more details.
808
877
  class AnalyzeEntitiesResponse; end
809
878
 
810
879
  # The syntax analysis request message.
@@ -827,9 +896,21 @@ module Google
827
896
  # @return [String]
828
897
  # The language of the text, which will be the same as the language specified
829
898
  # in the request or, if not specified, the automatically-detected language.
830
- # See +Document.language+ field for more details.
899
+ # See {Google::Cloud::Language::V1::Document#language Document#language} field for more details.
831
900
  class AnalyzeSyntaxResponse; end
832
901
 
902
+ # The document classification request message.
903
+ # @!attribute [rw] document
904
+ # @return [Google::Cloud::Language::V1::Document]
905
+ # Input document.
906
+ class ClassifyTextRequest; end
907
+
908
+ # The document classification response message.
909
+ # @!attribute [rw] categories
910
+ # @return [Array<Google::Cloud::Language::V1::ClassificationCategory>]
911
+ # Categories representing the input document.
912
+ class ClassifyTextResponse; end
913
+
833
914
  # The request message for the text annotation API, which can perform multiple
834
915
  # analysis types (sentiment, entities, and syntax) in one call.
835
916
  # @!attribute [rw] document
@@ -853,6 +934,12 @@ module Google
853
934
  # @!attribute [rw] extract_document_sentiment
854
935
  # @return [true, false]
855
936
  # Extract document-level sentiment.
937
+ # @!attribute [rw] extract_entity_sentiment
938
+ # @return [true, false]
939
+ # Extract entities and their associated sentiment.
940
+ # @!attribute [rw] classify_text
941
+ # @return [true, false]
942
+ # Classify the full document into categories.
856
943
  class Features; end
857
944
  end
858
945
 
@@ -860,26 +947,29 @@ module Google
860
947
  # @!attribute [rw] sentences
861
948
  # @return [Array<Google::Cloud::Language::V1::Sentence>]
862
949
  # Sentences in the input document. Populated if the user enables
863
- # AnnotateTextRequest::Features#extract_syntax.
950
+ # {Google::Cloud::Language::V1::AnnotateTextRequest::Features#extract_syntax AnnotateTextRequest::Features#extract_syntax}.
864
951
  # @!attribute [rw] tokens
865
952
  # @return [Array<Google::Cloud::Language::V1::Token>]
866
953
  # Tokens, along with their syntactic information, in the input document.
867
954
  # Populated if the user enables
868
- # AnnotateTextRequest::Features#extract_syntax.
955
+ # {Google::Cloud::Language::V1::AnnotateTextRequest::Features#extract_syntax AnnotateTextRequest::Features#extract_syntax}.
869
956
  # @!attribute [rw] entities
870
957
  # @return [Array<Google::Cloud::Language::V1::Entity>]
871
958
  # Entities, along with their semantic information, in the input document.
872
959
  # Populated if the user enables
873
- # AnnotateTextRequest::Features#extract_entities.
960
+ # {Google::Cloud::Language::V1::AnnotateTextRequest::Features#extract_entities AnnotateTextRequest::Features#extract_entities}.
874
961
  # @!attribute [rw] document_sentiment
875
962
  # @return [Google::Cloud::Language::V1::Sentiment]
876
963
  # The overall sentiment for the document. Populated if the user enables
877
- # AnnotateTextRequest::Features#extract_document_sentiment.
964
+ # {Google::Cloud::Language::V1::AnnotateTextRequest::Features#extract_document_sentiment AnnotateTextRequest::Features#extract_document_sentiment}.
878
965
  # @!attribute [rw] language
879
966
  # @return [String]
880
967
  # The language of the text, which will be the same as the language specified
881
968
  # in the request or, if not specified, the automatically-detected language.
882
- # See +Document.language+ field for more details.
969
+ # See {Google::Cloud::Language::V1::Document#language Document#language} field for more details.
970
+ # @!attribute [rw] categories
971
+ # @return [Array<Google::Cloud::Language::V1::ClassificationCategory>]
972
+ # Categories identified in the input document.
883
973
  class AnnotateTextResponse; end
884
974
 
885
975
  # Represents the text encoding that the caller uses to process the output.
@@ -0,0 +1,67 @@
1
+ # Copyright 2017, Google LLC 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
+ module Google
16
+ module Cloud
17
+ # rubocop:disable LineLength
18
+
19
+ ##
20
+ # # Ruby Client for Google Cloud Natural Language API ([Alpha](https://github.com/GoogleCloudPlatform/google-cloud-ruby#versioning))
21
+ #
22
+ # [Google Cloud Natural Language API][Product Documentation]:
23
+ # Google Cloud Natural Language API provides natural language understanding
24
+ # technologies to developers. Examples include sentiment analysis, entity
25
+ # recognition, and text annotations.
26
+ # - [Product Documentation][]
27
+ #
28
+ # ## Quick Start
29
+ # In order to use this library, you first need to go through the following
30
+ # steps:
31
+ #
32
+ # 1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project)
33
+ # 2. [Enable the Google Cloud Natural Language API.](https://console.cloud.google.com/apis/api/language)
34
+ # 3. [Setup Authentication.](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud/master/guides/authentication)
35
+ #
36
+ # ### Installation
37
+ # ```
38
+ # $ gem install google-cloud-language
39
+ # ```
40
+ #
41
+ # ### Preview
42
+ # #### LanguageServiceClient
43
+ # ```rb
44
+ # require "google/cloud/language"
45
+ #
46
+ # language_service_client = Google::Cloud::Language.new
47
+ # content = "Hello, world!"
48
+ # type = :PLAIN_TEXT
49
+ # document = { content: content, type: type }
50
+ # response = language_service_client.analyze_sentiment(document)
51
+ # ```
52
+ #
53
+ # ### Next Steps
54
+ # - Read the [Google Cloud Natural Language API Product documentation][Product Documentation]
55
+ # to learn more about the product and see How-to Guides.
56
+ # - View this [repository's main README](https://github.com/GoogleCloudPlatform/google-cloud-ruby/blob/master/README.md)
57
+ # to see the full list of Cloud APIs that we cover.
58
+ #
59
+ # [Product Documentation]: https://cloud.google.com/language
60
+ #
61
+ #
62
+ module Language
63
+ module V1
64
+ end
65
+ end
66
+ end
67
+ end