Skip to content

Commit 4311718

Browse files
yoshi-automationJustinBeckwith
authored andcommitted
fix: improve docstrings, and add more field validation (#224)
fix: improve docstrings, and add more field validation
1 parent d6f1688 commit 4311718

File tree

4 files changed

+147
-90
lines changed

4 files changed

+147
-90
lines changed

packages/google-cloud-language/protos/google/cloud/language/v1/language_service.proto

Lines changed: 85 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,53 @@ syntax = "proto3";
1818
package google.cloud.language.v1;
1919

2020
import "google/api/annotations.proto";
21+
import "google/api/client.proto";
22+
import "google/api/field_behavior.proto";
2123

2224
option go_package = "google.golang.org/genproto/googleapis/cloud/language/v1;language";
2325
option java_multiple_files = true;
2426
option java_outer_classname = "LanguageServiceProto";
2527
option java_package = "com.google.cloud.language.v1";
2628

29+
2730
// Provides text analysis operations such as sentiment analysis and entity
2831
// recognition.
2932
service LanguageService {
33+
option (google.api.default_host) = "language.googleapis.com";
34+
option (google.api.oauth_scopes) =
35+
"https://www.googleapis.com/auth/cloud-language,"
36+
"https://www.googleapis.com/auth/cloud-platform";
3037
// Analyzes the sentiment of the provided text.
31-
rpc AnalyzeSentiment(AnalyzeSentimentRequest)
32-
returns (AnalyzeSentimentResponse) {
38+
rpc AnalyzeSentiment(AnalyzeSentimentRequest) returns (AnalyzeSentimentResponse) {
3339
option (google.api.http) = {
3440
post: "/v1/documents:analyzeSentiment"
3541
body: "*"
3642
};
43+
option (google.api.method_signature) = "document,encoding_type";
44+
option (google.api.method_signature) = "document";
3745
}
3846

3947
// Finds named entities (currently proper names and common nouns) in the text
4048
// along with entity types, salience, mentions for each entity, and
4149
// other properties.
42-
rpc AnalyzeEntities(AnalyzeEntitiesRequest)
43-
returns (AnalyzeEntitiesResponse) {
50+
rpc AnalyzeEntities(AnalyzeEntitiesRequest) returns (AnalyzeEntitiesResponse) {
4451
option (google.api.http) = {
4552
post: "/v1/documents:analyzeEntities"
4653
body: "*"
4754
};
55+
option (google.api.method_signature) = "document,encoding_type";
56+
option (google.api.method_signature) = "document";
4857
}
4958

50-
// Finds entities, similar to
51-
// [AnalyzeEntities][google.cloud.language.v1.LanguageService.AnalyzeEntities]
52-
// in the text and analyzes sentiment associated with each entity and its
53-
// mentions.
54-
rpc AnalyzeEntitySentiment(AnalyzeEntitySentimentRequest)
55-
returns (AnalyzeEntitySentimentResponse) {
59+
// Finds entities, similar to [AnalyzeEntities][google.cloud.language.v1.LanguageService.AnalyzeEntities] in the text and analyzes
60+
// sentiment associated with each entity and its mentions.
61+
rpc AnalyzeEntitySentiment(AnalyzeEntitySentimentRequest) returns (AnalyzeEntitySentimentResponse) {
5662
option (google.api.http) = {
5763
post: "/v1/documents:analyzeEntitySentiment"
5864
body: "*"
5965
};
66+
option (google.api.method_signature) = "document,encoding_type";
67+
option (google.api.method_signature) = "document";
6068
}
6169

6270
// Analyzes the syntax of the text and provides sentence boundaries and
@@ -67,6 +75,8 @@ service LanguageService {
6775
post: "/v1/documents:analyzeSyntax"
6876
body: "*"
6977
};
78+
option (google.api.method_signature) = "document,encoding_type";
79+
option (google.api.method_signature) = "document";
7080
}
7181

7282
// Classifies a document into categories.
@@ -75,6 +85,7 @@ service LanguageService {
7585
post: "/v1/documents:classifyText"
7686
body: "*"
7787
};
88+
option (google.api.method_signature) = "document";
7889
}
7990

8091
// A convenience method that provides all the features that analyzeSentiment,
@@ -84,6 +95,8 @@ service LanguageService {
8495
post: "/v1/documents:annotateText"
8596
body: "*"
8697
};
98+
option (google.api.method_signature) = "document,features,encoding_type";
99+
option (google.api.method_signature) = "document,features";
87100
}
88101
}
89102

@@ -111,6 +124,7 @@ message Document {
111124
// Google Cloud Storage URI.
112125
oneof source {
113126
// The content of the input in string format.
127+
// Cloud audit logging exempt since it is based on user data.
114128
string content = 2;
115129

116130
// The Google Cloud Storage URI where the file content is located.
@@ -137,16 +151,19 @@ message Sentence {
137151
TextSpan text = 1;
138152

139153
// For calls to [AnalyzeSentiment][] or if
140-
// [AnnotateTextRequest.Features.extract_document_sentiment][google.cloud.language.v1.AnnotateTextRequest.Features.extract_document_sentiment]
141-
// is set to true, this field will contain the sentiment for the sentence.
154+
// [AnnotateTextRequest.Features.extract_document_sentiment][google.cloud.language.v1.AnnotateTextRequest.Features.extract_document_sentiment] is set to
155+
// true, this field will contain the sentiment for the sentence.
142156
Sentiment sentiment = 2;
143157
}
144158

145159
// Represents a phrase in the text that is a known entity, such as
146160
// a person, an organization, or location. The API associates information, such
147161
// as salience and mentions, with entities.
148162
message Entity {
149-
// The type of the entity.
163+
// The type of the entity. For most entity types, the associated metadata is a
164+
// Wikipedia URL (`wikipedia_url`) and Knowledge Graph MID (`mid`). The table
165+
// below lists the associated fields for entities that have different
166+
// metadata.
150167
enum Type {
151168
// Unknown
152169
UNKNOWN = 0;
@@ -163,28 +180,53 @@ message Entity {
163180
// Event
164181
EVENT = 4;
165182

166-
// Work of art
183+
// Artwork
167184
WORK_OF_ART = 5;
168185

169-
// Consumer goods
186+
// Consumer product
170187
CONSUMER_GOOD = 6;
171188

172-
// Other types
189+
// Other types of entities
173190
OTHER = 7;
174191

175-
// Phone number
192+
// Phone number<br><br>
193+
// The metadata lists the phone number, formatted according to local
194+
// convention, plus whichever additional elements appear in the text:<ul>
195+
// <li><code>number</code> &ndash; the actual number, broken down into
196+
// sections as per local convention</li> <li><code>national_prefix</code>
197+
// &ndash; country code, if detected</li> <li><code>area_code</code> &ndash;
198+
// region or area code, if detected</li> <li><code>extension</code> &ndash;
199+
// phone extension (to be dialed after connection), if detected</li></ul>
176200
PHONE_NUMBER = 9;
177201

178-
// Address
202+
// Address<br><br>
203+
// The metadata identifies the street number and locality plus whichever
204+
// additional elements appear in the text:<ul>
205+
// <li><code>street_number</code> &ndash; street number</li>
206+
// <li><code>locality</code> &ndash; city or town</li>
207+
// <li><code>street_name</code> &ndash; street/route name, if detected</li>
208+
// <li><code>postal_code</code> &ndash; postal code, if detected</li>
209+
// <li><code>country</code> &ndash; country, if detected</li>
210+
// <li><code>broad_region</code> &ndash; administrative area, such as the
211+
// state, if detected</li> <li><code>narrow_region</code> &ndash; smaller
212+
// administrative area, such as county, if detected</li>
213+
// <li><code>sublocality</code> &ndash; used in Asian addresses to demark a
214+
// district within a city, if detected</li></ul>
179215
ADDRESS = 10;
180216

181-
// Date
217+
// Date<br><br>
218+
// The metadata identifies the components of the date:<ul>
219+
// <li><code>year</code> &ndash; four digit year, if detected</li>
220+
// <li><code>month</code> &ndash; two digit month number, if detected</li>
221+
// <li><code>day</code> &ndash; two digit day number, if detected</li></ul>
182222
DATE = 11;
183223

184-
// Number
224+
// Number<br><br>
225+
// The metadata is the number itself.
185226
NUMBER = 12;
186227

187-
// Price
228+
// Price<br><br>
229+
// The metadata identifies the <code>value</code> and <code>currency</code>.
188230
PRICE = 13;
189231
}
190232

@@ -196,8 +238,9 @@ message Entity {
196238

197239
// Metadata associated with the entity.
198240
//
199-
// Currently, Wikipedia URLs and Knowledge Graph MIDs are provided, if
200-
// available. The associated keys are "wikipedia_url" and "mid", respectively.
241+
// For most entity types, the metadata is a Wikipedia URL (`wikipedia_url`)
242+
// and Knowledge Graph MID (`mid`), if they are available. For the metadata
243+
// associated with other entity types, see the Type table below.
201244
map<string, string> metadata = 3;
202245

203246
// The salience score associated with the entity in the [0, 1.0] range.
@@ -213,9 +256,9 @@ message Entity {
213256
repeated EntityMention mentions = 5;
214257

215258
// For calls to [AnalyzeEntitySentiment][] or if
216-
// [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v1.AnnotateTextRequest.Features.extract_entity_sentiment]
217-
// is set to true, this field will contain the aggregate sentiment expressed
218-
// for this entity in the provided document.
259+
// [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v1.AnnotateTextRequest.Features.extract_entity_sentiment] is set to
260+
// true, this field will contain the aggregate sentiment expressed for this
261+
// entity in the provided document.
219262
Sentiment sentiment = 6;
220263
}
221264

@@ -892,9 +935,9 @@ message EntityMention {
892935
Type type = 2;
893936

894937
// For calls to [AnalyzeEntitySentiment][] or if
895-
// [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v1.AnnotateTextRequest.Features.extract_entity_sentiment]
896-
// is set to true, this field will contain the sentiment expressed for this
897-
// mention of the entity in the provided document.
938+
// [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v1.AnnotateTextRequest.Features.extract_entity_sentiment] is set to
939+
// true, this field will contain the sentiment expressed for this mention of
940+
// the entity in the provided document.
898941
Sentiment sentiment = 3;
899942
}
900943

@@ -904,9 +947,7 @@ message TextSpan {
904947
string content = 1;
905948

906949
// The API calculates the beginning offset of the content in the original
907-
// document according to the
908-
// [EncodingType][google.cloud.language.v1.EncodingType] specified in the API
909-
// request.
950+
// document according to the [EncodingType][google.cloud.language.v1.EncodingType] specified in the API request.
910951
int32 begin_offset = 2;
911952
}
912953

@@ -924,7 +965,7 @@ message ClassificationCategory {
924965
// The sentiment analysis request message.
925966
message AnalyzeSentimentRequest {
926967
// Input document.
927-
Document document = 1;
968+
Document document = 1 [(google.api.field_behavior) = REQUIRED];
928969

929970
// The encoding type used by the API to calculate sentence offsets.
930971
EncodingType encoding_type = 2;
@@ -937,8 +978,7 @@ message AnalyzeSentimentResponse {
937978

938979
// The language of the text, which will be the same as the language specified
939980
// in the request or, if not specified, the automatically-detected language.
940-
// See [Document.language][google.cloud.language.v1.Document.language] field
941-
// for more details.
981+
// See [Document.language][google.cloud.language.v1.Document.language] field for more details.
942982
string language = 2;
943983

944984
// The sentiment for all the sentences in the document.
@@ -948,7 +988,7 @@ message AnalyzeSentimentResponse {
948988
// The entity-level sentiment analysis request message.
949989
message AnalyzeEntitySentimentRequest {
950990
// Input document.
951-
Document document = 1;
991+
Document document = 1 [(google.api.field_behavior) = REQUIRED];
952992

953993
// The encoding type used by the API to calculate offsets.
954994
EncodingType encoding_type = 2;
@@ -961,15 +1001,14 @@ message AnalyzeEntitySentimentResponse {
9611001

9621002
// The language of the text, which will be the same as the language specified
9631003
// in the request or, if not specified, the automatically-detected language.
964-
// See [Document.language][google.cloud.language.v1.Document.language] field
965-
// for more details.
1004+
// See [Document.language][google.cloud.language.v1.Document.language] field for more details.
9661005
string language = 2;
9671006
}
9681007

9691008
// The entity analysis request message.
9701009
message AnalyzeEntitiesRequest {
9711010
// Input document.
972-
Document document = 1;
1011+
Document document = 1 [(google.api.field_behavior) = REQUIRED];
9731012

9741013
// The encoding type used by the API to calculate offsets.
9751014
EncodingType encoding_type = 2;
@@ -982,15 +1021,14 @@ message AnalyzeEntitiesResponse {
9821021

9831022
// The language of the text, which will be the same as the language specified
9841023
// in the request or, if not specified, the automatically-detected language.
985-
// See [Document.language][google.cloud.language.v1.Document.language] field
986-
// for more details.
1024+
// See [Document.language][google.cloud.language.v1.Document.language] field for more details.
9871025
string language = 2;
9881026
}
9891027

9901028
// The syntax analysis request message.
9911029
message AnalyzeSyntaxRequest {
9921030
// Input document.
993-
Document document = 1;
1031+
Document document = 1 [(google.api.field_behavior) = REQUIRED];
9941032

9951033
// The encoding type used by the API to calculate offsets.
9961034
EncodingType encoding_type = 2;
@@ -1006,15 +1044,14 @@ message AnalyzeSyntaxResponse {
10061044

10071045
// The language of the text, which will be the same as the language specified
10081046
// in the request or, if not specified, the automatically-detected language.
1009-
// See [Document.language][google.cloud.language.v1.Document.language] field
1010-
// for more details.
1047+
// See [Document.language][google.cloud.language.v1.Document.language] field for more details.
10111048
string language = 3;
10121049
}
10131050

10141051
// The document classification request message.
10151052
message ClassifyTextRequest {
10161053
// Input document.
1017-
Document document = 1;
1054+
Document document = 1 [(google.api.field_behavior) = REQUIRED];
10181055
}
10191056

10201057
// The document classification response message.
@@ -1046,10 +1083,10 @@ message AnnotateTextRequest {
10461083
}
10471084

10481085
// Input document.
1049-
Document document = 1;
1086+
Document document = 1 [(google.api.field_behavior) = REQUIRED];
10501087

10511088
// The enabled features.
1052-
Features features = 2;
1089+
Features features = 2 [(google.api.field_behavior) = REQUIRED];
10531090

10541091
// The encoding type used by the API to calculate offsets.
10551092
EncodingType encoding_type = 3;
@@ -1077,8 +1114,7 @@ message AnnotateTextResponse {
10771114

10781115
// The language of the text, which will be the same as the language specified
10791116
// in the request or, if not specified, the automatically-detected language.
1080-
// See [Document.language][google.cloud.language.v1.Document.language] field
1081-
// for more details.
1117+
// See [Document.language][google.cloud.language.v1.Document.language] field for more details.
10821118
string language = 5;
10831119

10841120
// Categories identified in the input document.

0 commit comments

Comments
 (0)