1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871
// This file is @generated by prost-build.
/// Represents the input to API methods.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Document {
/// Required. If the type is not set or is `TYPE_UNSPECIFIED`,
/// returns an `INVALID_ARGUMENT` error.
#[prost(enumeration = "document::Type", tag = "1")]
pub r#type: i32,
/// Optional. The language of the document (if not specified, the language is
/// automatically detected). Both ISO and BCP-47 language codes are
/// accepted.<br>
/// [Language
/// Support](<https://cloud.google.com/natural-language/docs/languages>) lists
/// currently supported languages for each API method. If the language (either
/// specified by the caller or automatically detected) is not supported by the
/// called API method, an `INVALID_ARGUMENT` error is returned.
#[prost(string, tag = "4")]
pub language_code: ::prost::alloc::string::String,
/// The source of the document: a string containing the content or a
/// Google Cloud Storage URI.
#[prost(oneof = "document::Source", tags = "2, 3")]
pub source: ::core::option::Option<document::Source>,
}
/// Nested message and enum types in `Document`.
pub mod document {
/// The document types enum.
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
::prost::Enumeration
)]
#[repr(i32)]
pub enum Type {
/// The content type is not specified.
Unspecified = 0,
/// Plain text
PlainText = 1,
/// HTML
Html = 2,
}
impl Type {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
Type::Unspecified => "TYPE_UNSPECIFIED",
Type::PlainText => "PLAIN_TEXT",
Type::Html => "HTML",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"TYPE_UNSPECIFIED" => Some(Self::Unspecified),
"PLAIN_TEXT" => Some(Self::PlainText),
"HTML" => Some(Self::Html),
_ => None,
}
}
}
/// The source of the document: a string containing the content or a
/// Google Cloud Storage URI.
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum Source {
/// The content of the input in string format.
/// Cloud audit logging exempt since it is based on user data.
#[prost(string, tag = "2")]
Content(::prost::alloc::string::String),
/// The Google Cloud Storage URI where the file content is located.
/// This URI must be of the form: gs://bucket_name/object_name. For more
/// details, see <https://cloud.google.com/storage/docs/reference-uris.>
/// NOTE: Cloud Storage object versioning is not supported.
#[prost(string, tag = "3")]
GcsContentUri(::prost::alloc::string::String),
}
}
/// Represents a sentence in the input document.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Sentence {
/// The sentence text.
#[prost(message, optional, tag = "1")]
pub text: ::core::option::Option<TextSpan>,
/// For calls to [AnalyzeSentiment][] or if
/// [AnnotateTextRequest.Features.extract_document_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment]
/// is set to true, this field will contain the sentiment for the sentence.
#[prost(message, optional, tag = "2")]
pub sentiment: ::core::option::Option<Sentiment>,
}
/// Represents a phrase in the text that is a known entity, such as
/// a person, an organization, or location. The API associates information, such
/// as probability and mentions, with entities.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Entity {
/// The representative name for the entity.
#[prost(string, tag = "1")]
pub name: ::prost::alloc::string::String,
/// The entity type.
#[prost(enumeration = "entity::Type", tag = "2")]
pub r#type: i32,
/// Metadata associated with the entity.
///
/// For the metadata
/// associated with other entity types, see the Type table below.
#[prost(btree_map = "string, string", tag = "3")]
pub metadata: ::prost::alloc::collections::BTreeMap<
::prost::alloc::string::String,
::prost::alloc::string::String,
>,
/// The mentions of this entity in the input document. The API currently
/// supports proper noun mentions.
#[prost(message, repeated, tag = "5")]
pub mentions: ::prost::alloc::vec::Vec<EntityMention>,
/// For calls to [AnalyzeEntitySentiment][] or if
/// [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entity_sentiment]
/// is set to true, this field will contain the aggregate sentiment expressed
/// for this entity in the provided document.
#[prost(message, optional, tag = "6")]
pub sentiment: ::core::option::Option<Sentiment>,
}
/// Nested message and enum types in `Entity`.
pub mod entity {
/// The type of the entity. The table
/// below lists the associated fields for entities that have different
/// metadata.
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
::prost::Enumeration
)]
#[repr(i32)]
pub enum Type {
/// Unknown
Unknown = 0,
/// Person
Person = 1,
/// Location
Location = 2,
/// Organization
Organization = 3,
/// Event
Event = 4,
/// Artwork
WorkOfArt = 5,
/// Consumer product
ConsumerGood = 6,
/// Other types of entities
Other = 7,
/// Phone number
///
/// The metadata lists the phone number, formatted according to local
/// convention, plus whichever additional elements appear in the text:
///
/// * `number` - the actual number, broken down into sections as per local
/// convention
/// * `national_prefix` - country code, if detected
/// * `area_code` - region or area code, if detected
/// * `extension` - phone extension (to be dialed after connection), if
/// detected
PhoneNumber = 9,
/// Address
///
/// The metadata identifies the street number and locality plus whichever
/// additional elements appear in the text:
///
/// * `street_number` - street number
/// * `locality` - city or town
/// * `street_name` - street/route name, if detected
/// * `postal_code` - postal code, if detected
/// * `country` - country, if detected
/// * `broad_region` - administrative area, such as the state, if detected
/// * `narrow_region` - smaller administrative area, such as county, if
/// detected
/// * `sublocality` - used in Asian addresses to demark a district within a
/// city, if detected
Address = 10,
/// Date
///
/// The metadata identifies the components of the date:
///
/// * `year` - four digit year, if detected
/// * `month` - two digit month number, if detected
/// * `day` - two digit day number, if detected
Date = 11,
/// Number
///
/// The metadata is the number itself.
Number = 12,
/// Price
///
/// The metadata identifies the `value` and `currency`.
Price = 13,
}
impl Type {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
Type::Unknown => "UNKNOWN",
Type::Person => "PERSON",
Type::Location => "LOCATION",
Type::Organization => "ORGANIZATION",
Type::Event => "EVENT",
Type::WorkOfArt => "WORK_OF_ART",
Type::ConsumerGood => "CONSUMER_GOOD",
Type::Other => "OTHER",
Type::PhoneNumber => "PHONE_NUMBER",
Type::Address => "ADDRESS",
Type::Date => "DATE",
Type::Number => "NUMBER",
Type::Price => "PRICE",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"UNKNOWN" => Some(Self::Unknown),
"PERSON" => Some(Self::Person),
"LOCATION" => Some(Self::Location),
"ORGANIZATION" => Some(Self::Organization),
"EVENT" => Some(Self::Event),
"WORK_OF_ART" => Some(Self::WorkOfArt),
"CONSUMER_GOOD" => Some(Self::ConsumerGood),
"OTHER" => Some(Self::Other),
"PHONE_NUMBER" => Some(Self::PhoneNumber),
"ADDRESS" => Some(Self::Address),
"DATE" => Some(Self::Date),
"NUMBER" => Some(Self::Number),
"PRICE" => Some(Self::Price),
_ => None,
}
}
}
}
/// Represents the feeling associated with the entire text or entities in
/// the text.
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
pub struct Sentiment {
/// A non-negative number in the [0, +inf) range, which represents
/// the absolute magnitude of sentiment regardless of score (positive or
/// negative).
#[prost(float, tag = "1")]
pub magnitude: f32,
/// Sentiment score between -1.0 (negative sentiment) and 1.0
/// (positive sentiment).
#[prost(float, tag = "2")]
pub score: f32,
}
/// Represents a mention for an entity in the text. Currently, proper noun
/// mentions are supported.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct EntityMention {
/// The mention text.
#[prost(message, optional, tag = "1")]
pub text: ::core::option::Option<TextSpan>,
/// The type of the entity mention.
#[prost(enumeration = "entity_mention::Type", tag = "2")]
pub r#type: i32,
/// For calls to [AnalyzeEntitySentiment][] or if
/// [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entity_sentiment]
/// is set to true, this field will contain the sentiment expressed for this
/// mention of the entity in the provided document.
#[prost(message, optional, tag = "3")]
pub sentiment: ::core::option::Option<Sentiment>,
/// Probability score associated with the entity.
///
/// The score shows the probability of the entity mention being the entity
/// type. The score is in (0, 1] range.
#[prost(float, tag = "4")]
pub probability: f32,
}
/// Nested message and enum types in `EntityMention`.
pub mod entity_mention {
/// The supported types of mentions.
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
::prost::Enumeration
)]
#[repr(i32)]
pub enum Type {
/// Unknown
Unknown = 0,
/// Proper name
Proper = 1,
/// Common noun (or noun compound)
Common = 2,
}
impl Type {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
Type::Unknown => "TYPE_UNKNOWN",
Type::Proper => "PROPER",
Type::Common => "COMMON",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"TYPE_UNKNOWN" => Some(Self::Unknown),
"PROPER" => Some(Self::Proper),
"COMMON" => Some(Self::Common),
_ => None,
}
}
}
}
/// Represents a text span in the input document.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct TextSpan {
/// The content of the text span, which is a substring of the document.
#[prost(string, tag = "1")]
pub content: ::prost::alloc::string::String,
/// The API calculates the beginning offset of the content in the original
/// document according to the
/// [EncodingType][google.cloud.language.v2.EncodingType] specified in the API
/// request.
#[prost(int32, tag = "2")]
pub begin_offset: i32,
}
/// Represents a category returned from the text classifier.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ClassificationCategory {
/// The name of the category representing the document.
#[prost(string, tag = "1")]
pub name: ::prost::alloc::string::String,
/// The classifier's confidence of the category. Number represents how certain
/// the classifier is that this category represents the given text.
#[prost(float, tag = "2")]
pub confidence: f32,
/// Optional. The classifier's severity of the category. This is only present
/// when the ModerateTextRequest.ModelVersion is set to MODEL_VERSION_2, and
/// the corresponding category has a severity score.
#[prost(float, tag = "3")]
pub severity: f32,
}
/// The sentiment analysis request message.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AnalyzeSentimentRequest {
/// Required. Input document.
#[prost(message, optional, tag = "1")]
pub document: ::core::option::Option<Document>,
/// The encoding type used by the API to calculate sentence offsets.
#[prost(enumeration = "EncodingType", tag = "2")]
pub encoding_type: i32,
}
/// The sentiment analysis response message.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AnalyzeSentimentResponse {
/// The overall sentiment of the input document.
#[prost(message, optional, tag = "1")]
pub document_sentiment: ::core::option::Option<Sentiment>,
/// The language of the text, which will be the same as the language specified
/// in the request or, if not specified, the automatically-detected language.
/// See [Document.language][] field for more details.
#[prost(string, tag = "2")]
pub language_code: ::prost::alloc::string::String,
/// The sentiment for all the sentences in the document.
#[prost(message, repeated, tag = "3")]
pub sentences: ::prost::alloc::vec::Vec<Sentence>,
/// Whether the language is officially supported. The API may still return a
/// response when the language is not supported, but it is on a best effort
/// basis.
#[prost(bool, tag = "4")]
pub language_supported: bool,
}
/// The entity analysis request message.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AnalyzeEntitiesRequest {
/// Required. Input document.
#[prost(message, optional, tag = "1")]
pub document: ::core::option::Option<Document>,
/// The encoding type used by the API to calculate offsets.
#[prost(enumeration = "EncodingType", tag = "2")]
pub encoding_type: i32,
}
/// The entity analysis response message.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AnalyzeEntitiesResponse {
/// The recognized entities in the input document.
#[prost(message, repeated, tag = "1")]
pub entities: ::prost::alloc::vec::Vec<Entity>,
/// The language of the text, which will be the same as the language specified
/// in the request or, if not specified, the automatically-detected language.
/// See [Document.language][] field for more details.
#[prost(string, tag = "2")]
pub language_code: ::prost::alloc::string::String,
/// Whether the language is officially supported. The API may still return a
/// response when the language is not supported, but it is on a best effort
/// basis.
#[prost(bool, tag = "3")]
pub language_supported: bool,
}
/// The document classification request message.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ClassifyTextRequest {
/// Required. Input document.
#[prost(message, optional, tag = "1")]
pub document: ::core::option::Option<Document>,
}
/// The document classification response message.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ClassifyTextResponse {
/// Categories representing the input document.
#[prost(message, repeated, tag = "1")]
pub categories: ::prost::alloc::vec::Vec<ClassificationCategory>,
/// The language of the text, which will be the same as the language specified
/// in the request or, if not specified, the automatically-detected language.
/// See [Document.language][] field for more details.
#[prost(string, tag = "2")]
pub language_code: ::prost::alloc::string::String,
/// Whether the language is officially supported. The API may still return a
/// response when the language is not supported, but it is on a best effort
/// basis.
#[prost(bool, tag = "3")]
pub language_supported: bool,
}
/// The document moderation request message.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ModerateTextRequest {
/// Required. Input document.
#[prost(message, optional, tag = "1")]
pub document: ::core::option::Option<Document>,
/// Optional. The model version to use for ModerateText.
#[prost(enumeration = "moderate_text_request::ModelVersion", tag = "2")]
pub model_version: i32,
}
/// Nested message and enum types in `ModerateTextRequest`.
pub mod moderate_text_request {
/// The model version to use for ModerateText.
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
::prost::Enumeration
)]
#[repr(i32)]
pub enum ModelVersion {
/// The default model version.
Unspecified = 0,
/// Use the v1 model, this model is used by default when not provided.
/// The v1 model only returns probability (confidence) score for each
/// category.
ModelVersion1 = 1,
/// Use the v2 model.
/// The v2 model only returns probability (confidence) score for each
/// category, and returns severity score for a subset of the categories.
ModelVersion2 = 2,
}
impl ModelVersion {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
ModelVersion::Unspecified => "MODEL_VERSION_UNSPECIFIED",
ModelVersion::ModelVersion1 => "MODEL_VERSION_1",
ModelVersion::ModelVersion2 => "MODEL_VERSION_2",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"MODEL_VERSION_UNSPECIFIED" => Some(Self::Unspecified),
"MODEL_VERSION_1" => Some(Self::ModelVersion1),
"MODEL_VERSION_2" => Some(Self::ModelVersion2),
_ => None,
}
}
}
}
/// The document moderation response message.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ModerateTextResponse {
/// Harmful and sensitive categories representing the input document.
#[prost(message, repeated, tag = "1")]
pub moderation_categories: ::prost::alloc::vec::Vec<ClassificationCategory>,
/// The language of the text, which will be the same as the language specified
/// in the request or, if not specified, the automatically-detected language.
/// See [Document.language][] field for more details.
#[prost(string, tag = "2")]
pub language_code: ::prost::alloc::string::String,
/// Whether the language is officially supported. The API may still return a
/// response when the language is not supported, but it is on a best effort
/// basis.
#[prost(bool, tag = "3")]
pub language_supported: bool,
}
/// The request message for the text annotation API, which can perform multiple
/// analysis types in one call.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AnnotateTextRequest {
/// Required. Input document.
#[prost(message, optional, tag = "1")]
pub document: ::core::option::Option<Document>,
/// Required. The enabled features.
#[prost(message, optional, tag = "2")]
pub features: ::core::option::Option<annotate_text_request::Features>,
/// The encoding type used by the API to calculate offsets.
#[prost(enumeration = "EncodingType", tag = "3")]
pub encoding_type: i32,
}
/// Nested message and enum types in `AnnotateTextRequest`.
pub mod annotate_text_request {
/// All available features.
/// Setting each one to true will enable that specific analysis for the input.
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
pub struct Features {
/// Optional. Extract entities.
#[prost(bool, tag = "1")]
pub extract_entities: bool,
/// Optional. Extract document-level sentiment.
#[prost(bool, tag = "2")]
pub extract_document_sentiment: bool,
/// Optional. Classify the full document into categories.
#[prost(bool, tag = "4")]
pub classify_text: bool,
/// Optional. Moderate the document for harmful and sensitive categories.
#[prost(bool, tag = "5")]
pub moderate_text: bool,
}
}
/// The text annotations response message.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AnnotateTextResponse {
/// Sentences in the input document. Populated if the user enables
/// [AnnotateTextRequest.Features.extract_document_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment].
#[prost(message, repeated, tag = "1")]
pub sentences: ::prost::alloc::vec::Vec<Sentence>,
/// Entities, along with their semantic information, in the input document.
/// Populated if the user enables
/// [AnnotateTextRequest.Features.extract_entities][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entities]
/// or
/// [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entity_sentiment].
#[prost(message, repeated, tag = "2")]
pub entities: ::prost::alloc::vec::Vec<Entity>,
/// The overall sentiment for the document. Populated if the user enables
/// [AnnotateTextRequest.Features.extract_document_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment].
#[prost(message, optional, tag = "3")]
pub document_sentiment: ::core::option::Option<Sentiment>,
/// The language of the text, which will be the same as the language specified
/// in the request or, if not specified, the automatically-detected language.
/// See [Document.language][] field for more details.
#[prost(string, tag = "4")]
pub language_code: ::prost::alloc::string::String,
/// Categories identified in the input document.
#[prost(message, repeated, tag = "5")]
pub categories: ::prost::alloc::vec::Vec<ClassificationCategory>,
/// Harmful and sensitive categories identified in the input document.
#[prost(message, repeated, tag = "6")]
pub moderation_categories: ::prost::alloc::vec::Vec<ClassificationCategory>,
/// Whether the language is officially supported by all requested features.
/// The API may still return a response when the language is not supported, but
/// it is on a best effort basis.
#[prost(bool, tag = "7")]
pub language_supported: bool,
}
/// Represents the text encoding that the caller uses to process the output.
/// Providing an `EncodingType` is recommended because the API provides the
/// beginning offsets for various outputs, such as tokens and mentions, and
/// languages that natively use different text encodings may access offsets
/// differently.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum EncodingType {
/// If `EncodingType` is not specified, encoding-dependent information (such as
/// `begin_offset`) will be set at `-1`.
None = 0,
/// Encoding-dependent information (such as `begin_offset`) is calculated based
/// on the UTF-8 encoding of the input. C++ and Go are examples of languages
/// that use this encoding natively.
Utf8 = 1,
/// Encoding-dependent information (such as `begin_offset`) is calculated based
/// on the UTF-16 encoding of the input. Java and JavaScript are examples of
/// languages that use this encoding natively.
Utf16 = 2,
/// Encoding-dependent information (such as `begin_offset`) is calculated based
/// on the UTF-32 encoding of the input. Python is an example of a language
/// that uses this encoding natively.
Utf32 = 3,
}
impl EncodingType {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
EncodingType::None => "NONE",
EncodingType::Utf8 => "UTF8",
EncodingType::Utf16 => "UTF16",
EncodingType::Utf32 => "UTF32",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"NONE" => Some(Self::None),
"UTF8" => Some(Self::Utf8),
"UTF16" => Some(Self::Utf16),
"UTF32" => Some(Self::Utf32),
_ => None,
}
}
}
/// Generated client implementations.
pub mod language_service_client {
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
use tonic::codegen::*;
use tonic::codegen::http::Uri;
/// Provides text analysis operations such as sentiment analysis and entity
/// recognition.
#[derive(Debug, Clone)]
pub struct LanguageServiceClient<T> {
inner: tonic::client::Grpc<T>,
}
impl<T> LanguageServiceClient<T>
where
T: tonic::client::GrpcService<tonic::body::BoxBody>,
T::Error: Into<StdError>,
T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
<T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
{
pub fn new(inner: T) -> Self {
let inner = tonic::client::Grpc::new(inner);
Self { inner }
}
pub fn with_origin(inner: T, origin: Uri) -> Self {
let inner = tonic::client::Grpc::with_origin(inner, origin);
Self { inner }
}
pub fn with_interceptor<F>(
inner: T,
interceptor: F,
) -> LanguageServiceClient<InterceptedService<T, F>>
where
F: tonic::service::Interceptor,
T::ResponseBody: Default,
T: tonic::codegen::Service<
http::Request<tonic::body::BoxBody>,
Response = http::Response<
<T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
>,
>,
<T as tonic::codegen::Service<
http::Request<tonic::body::BoxBody>,
>>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
{
LanguageServiceClient::new(InterceptedService::new(inner, interceptor))
}
/// Compress requests with the given encoding.
///
/// This requires the server to support it otherwise it might respond with an
/// error.
#[must_use]
pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
self.inner = self.inner.send_compressed(encoding);
self
}
/// Enable decompressing responses.
#[must_use]
pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
self.inner = self.inner.accept_compressed(encoding);
self
}
/// Limits the maximum size of a decoded message.
///
/// Default: `4MB`
#[must_use]
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
self.inner = self.inner.max_decoding_message_size(limit);
self
}
/// Limits the maximum size of an encoded message.
///
/// Default: `usize::MAX`
#[must_use]
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
self.inner = self.inner.max_encoding_message_size(limit);
self
}
/// Analyzes the sentiment of the provided text.
pub async fn analyze_sentiment(
&mut self,
request: impl tonic::IntoRequest<super::AnalyzeSentimentRequest>,
) -> std::result::Result<
tonic::Response<super::AnalyzeSentimentResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/google.cloud.language.v2.LanguageService/AnalyzeSentiment",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"google.cloud.language.v2.LanguageService",
"AnalyzeSentiment",
),
);
self.inner.unary(req, path, codec).await
}
/// Finds named entities (currently proper names and common nouns) in the text
/// along with entity types, probability, mentions for each entity, and
/// other properties.
pub async fn analyze_entities(
&mut self,
request: impl tonic::IntoRequest<super::AnalyzeEntitiesRequest>,
) -> std::result::Result<
tonic::Response<super::AnalyzeEntitiesResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/google.cloud.language.v2.LanguageService/AnalyzeEntities",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"google.cloud.language.v2.LanguageService",
"AnalyzeEntities",
),
);
self.inner.unary(req, path, codec).await
}
/// Classifies a document into categories.
pub async fn classify_text(
&mut self,
request: impl tonic::IntoRequest<super::ClassifyTextRequest>,
) -> std::result::Result<
tonic::Response<super::ClassifyTextResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/google.cloud.language.v2.LanguageService/ClassifyText",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"google.cloud.language.v2.LanguageService",
"ClassifyText",
),
);
self.inner.unary(req, path, codec).await
}
/// Moderates a document for harmful and sensitive categories.
pub async fn moderate_text(
&mut self,
request: impl tonic::IntoRequest<super::ModerateTextRequest>,
) -> std::result::Result<
tonic::Response<super::ModerateTextResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/google.cloud.language.v2.LanguageService/ModerateText",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"google.cloud.language.v2.LanguageService",
"ModerateText",
),
);
self.inner.unary(req, path, codec).await
}
/// A convenience method that provides all features in one call.
pub async fn annotate_text(
&mut self,
request: impl tonic::IntoRequest<super::AnnotateTextRequest>,
) -> std::result::Result<
tonic::Response<super::AnnotateTextResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/google.cloud.language.v2.LanguageService/AnnotateText",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"google.cloud.language.v2.LanguageService",
"AnnotateText",
),
);
self.inner.unary(req, path, codec).await
}
}
}