google_cloud_language_v2/
model.rs

1// Copyright 2025 Google LLC
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//     https://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// Code generated by sidekick. DO NOT EDIT.
16
17#![allow(rustdoc::redundant_explicit_links)]
18#![allow(rustdoc::broken_intra_doc_links)]
19#![no_implicit_prelude]
20extern crate async_trait;
21extern crate bytes;
22extern crate gax;
23extern crate gaxi;
24extern crate lazy_static;
25extern crate reqwest;
26extern crate serde;
27extern crate serde_json;
28extern crate serde_with;
29extern crate std;
30extern crate tracing;
31extern crate wkt;
32
33/// Represents the input to API methods.
34#[serde_with::serde_as]
35#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
36#[serde(default, rename_all = "camelCase")]
37#[non_exhaustive]
38pub struct Document {
39    /// Required. If the type is not set or is `TYPE_UNSPECIFIED`,
40    /// returns an `INVALID_ARGUMENT` error.
41    #[serde(rename = "type")]
42    pub r#type: crate::model::document::Type,
43
44    /// Optional. The language of the document (if not specified, the language is
45    /// automatically detected). Both ISO and BCP-47 language codes are
46    /// accepted.\<br\>
47    /// [Language
48    /// Support](https://cloud.google.com/natural-language/docs/languages) lists
49    /// currently supported languages for each API method. If the language (either
50    /// specified by the caller or automatically detected) is not supported by the
51    /// called API method, an `INVALID_ARGUMENT` error is returned.
52    #[serde(skip_serializing_if = "std::string::String::is_empty")]
53    pub language_code: std::string::String,
54
55    /// The source of the document: a string containing the content or a
56    /// Google Cloud Storage URI.
57    #[serde(flatten, skip_serializing_if = "std::option::Option::is_none")]
58    pub source: std::option::Option<crate::model::document::Source>,
59
60    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
61    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
62}
63
64impl Document {
65    pub fn new() -> Self {
66        std::default::Default::default()
67    }
68
69    /// Sets the value of [r#type][crate::model::Document::type].
70    pub fn set_type<T: std::convert::Into<crate::model::document::Type>>(mut self, v: T) -> Self {
71        self.r#type = v.into();
72        self
73    }
74
75    /// Sets the value of [language_code][crate::model::Document::language_code].
76    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
77        self.language_code = v.into();
78        self
79    }
80
81    /// Sets the value of [source][crate::model::Document::source].
82    ///
83    /// Note that all the setters affecting `source` are mutually
84    /// exclusive.
85    pub fn set_source<
86        T: std::convert::Into<std::option::Option<crate::model::document::Source>>,
87    >(
88        mut self,
89        v: T,
90    ) -> Self {
91        self.source = v.into();
92        self
93    }
94
95    /// The value of [source][crate::model::Document::source]
96    /// if it holds a `Content`, `None` if the field is not set or
97    /// holds a different branch.
98    pub fn content(&self) -> std::option::Option<&std::string::String> {
99        #[allow(unreachable_patterns)]
100        self.source.as_ref().and_then(|v| match v {
101            crate::model::document::Source::Content(v) => std::option::Option::Some(v),
102            _ => std::option::Option::None,
103        })
104    }
105
106    /// The value of [source][crate::model::Document::source]
107    /// if it holds a `GcsContentUri`, `None` if the field is not set or
108    /// holds a different branch.
109    pub fn gcs_content_uri(&self) -> std::option::Option<&std::string::String> {
110        #[allow(unreachable_patterns)]
111        self.source.as_ref().and_then(|v| match v {
112            crate::model::document::Source::GcsContentUri(v) => std::option::Option::Some(v),
113            _ => std::option::Option::None,
114        })
115    }
116
117    /// Sets the value of [source][crate::model::Document::source]
118    /// to hold a `Content`.
119    ///
120    /// Note that all the setters affecting `source` are
121    /// mutually exclusive.
122    pub fn set_content<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
123        self.source = std::option::Option::Some(crate::model::document::Source::Content(v.into()));
124        self
125    }
126
127    /// Sets the value of [source][crate::model::Document::source]
128    /// to hold a `GcsContentUri`.
129    ///
130    /// Note that all the setters affecting `source` are
131    /// mutually exclusive.
132    pub fn set_gcs_content_uri<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
133        self.source =
134            std::option::Option::Some(crate::model::document::Source::GcsContentUri(v.into()));
135        self
136    }
137}
138
139impl wkt::message::Message for Document {
140    fn typename() -> &'static str {
141        "type.googleapis.com/google.cloud.language.v2.Document"
142    }
143}
144
145/// Defines additional types related to [Document].
146pub mod document {
147    #[allow(unused_imports)]
148    use super::*;
149
150    /// The document types enum.
151    #[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)]
152    pub struct Type(i32);
153
154    impl Type {
155        /// The content type is not specified.
156        pub const TYPE_UNSPECIFIED: Type = Type::new(0);
157
158        /// Plain text
159        pub const PLAIN_TEXT: Type = Type::new(1);
160
161        /// HTML
162        pub const HTML: Type = Type::new(2);
163
164        /// Creates a new Type instance.
165        pub(crate) const fn new(value: i32) -> Self {
166            Self(value)
167        }
168
169        /// Gets the enum value.
170        pub fn value(&self) -> i32 {
171            self.0
172        }
173
174        /// Gets the enum value as a string.
175        pub fn as_str_name(&self) -> std::borrow::Cow<'static, str> {
176            match self.0 {
177                0 => std::borrow::Cow::Borrowed("TYPE_UNSPECIFIED"),
178                1 => std::borrow::Cow::Borrowed("PLAIN_TEXT"),
179                2 => std::borrow::Cow::Borrowed("HTML"),
180                _ => std::borrow::Cow::Owned(std::format!("UNKNOWN-VALUE:{}", self.0)),
181            }
182        }
183
184        /// Creates an enum value from the value name.
185        pub fn from_str_name(name: &str) -> std::option::Option<Self> {
186            match name {
187                "TYPE_UNSPECIFIED" => std::option::Option::Some(Self::TYPE_UNSPECIFIED),
188                "PLAIN_TEXT" => std::option::Option::Some(Self::PLAIN_TEXT),
189                "HTML" => std::option::Option::Some(Self::HTML),
190                _ => std::option::Option::None,
191            }
192        }
193    }
194
195    impl std::convert::From<i32> for Type {
196        fn from(value: i32) -> Self {
197            Self::new(value)
198        }
199    }
200
201    impl std::default::Default for Type {
202        fn default() -> Self {
203            Self::new(0)
204        }
205    }
206
207    /// The source of the document: a string containing the content or a
208    /// Google Cloud Storage URI.
209    #[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)]
210    #[serde(rename_all = "camelCase")]
211    #[non_exhaustive]
212    pub enum Source {
213        /// The content of the input in string format.
214        /// Cloud audit logging exempt since it is based on user data.
215        Content(std::string::String),
216        /// The Google Cloud Storage URI where the file content is located.
217        /// This URI must be of the form: gs://bucket_name/object_name. For more
218        /// details, see <https://cloud.google.com/storage/docs/reference-uris>.
219        /// NOTE: Cloud Storage object versioning is not supported.
220        GcsContentUri(std::string::String),
221    }
222}
223
224/// Represents a sentence in the input document.
225#[serde_with::serde_as]
226#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
227#[serde(default, rename_all = "camelCase")]
228#[non_exhaustive]
229pub struct Sentence {
230    /// The sentence text.
231    #[serde(skip_serializing_if = "std::option::Option::is_none")]
232    pub text: std::option::Option<crate::model::TextSpan>,
233
234    /// For calls to [AnalyzeSentiment][] or if
235    /// [AnnotateTextRequest.Features.extract_document_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment]
236    /// is set to true, this field will contain the sentiment for the sentence.
237    ///
238    /// [google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment]: crate::model::annotate_text_request::Features::extract_document_sentiment
239    #[serde(skip_serializing_if = "std::option::Option::is_none")]
240    pub sentiment: std::option::Option<crate::model::Sentiment>,
241
242    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
243    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
244}
245
246impl Sentence {
247    pub fn new() -> Self {
248        std::default::Default::default()
249    }
250
251    /// Sets the value of [text][crate::model::Sentence::text].
252    pub fn set_text<T: std::convert::Into<std::option::Option<crate::model::TextSpan>>>(
253        mut self,
254        v: T,
255    ) -> Self {
256        self.text = v.into();
257        self
258    }
259
260    /// Sets the value of [sentiment][crate::model::Sentence::sentiment].
261    pub fn set_sentiment<T: std::convert::Into<std::option::Option<crate::model::Sentiment>>>(
262        mut self,
263        v: T,
264    ) -> Self {
265        self.sentiment = v.into();
266        self
267    }
268}
269
270impl wkt::message::Message for Sentence {
271    fn typename() -> &'static str {
272        "type.googleapis.com/google.cloud.language.v2.Sentence"
273    }
274}
275
276/// Represents a phrase in the text that is a known entity, such as
277/// a person, an organization, or location. The API associates information, such
278/// as probability and mentions, with entities.
279#[serde_with::serde_as]
280#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
281#[serde(default, rename_all = "camelCase")]
282#[non_exhaustive]
283pub struct Entity {
284    /// The representative name for the entity.
285    #[serde(skip_serializing_if = "std::string::String::is_empty")]
286    pub name: std::string::String,
287
288    /// The entity type.
289    #[serde(rename = "type")]
290    pub r#type: crate::model::entity::Type,
291
292    /// Metadata associated with the entity.
293    ///
294    /// For the metadata
295    /// associated with other entity types, see the Type table below.
296    #[serde(skip_serializing_if = "std::collections::HashMap::is_empty")]
297    pub metadata: std::collections::HashMap<std::string::String, std::string::String>,
298
299    /// The mentions of this entity in the input document. The API currently
300    /// supports proper noun mentions.
301    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
302    pub mentions: std::vec::Vec<crate::model::EntityMention>,
303
304    /// For calls to [AnalyzeEntitySentiment][] or if
305    /// [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entity_sentiment]
306    /// is set to true, this field will contain the aggregate sentiment expressed
307    /// for this entity in the provided document.
308    #[serde(skip_serializing_if = "std::option::Option::is_none")]
309    pub sentiment: std::option::Option<crate::model::Sentiment>,
310
311    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
312    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
313}
314
315impl Entity {
316    pub fn new() -> Self {
317        std::default::Default::default()
318    }
319
320    /// Sets the value of [name][crate::model::Entity::name].
321    pub fn set_name<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
322        self.name = v.into();
323        self
324    }
325
326    /// Sets the value of [r#type][crate::model::Entity::type].
327    pub fn set_type<T: std::convert::Into<crate::model::entity::Type>>(mut self, v: T) -> Self {
328        self.r#type = v.into();
329        self
330    }
331
332    /// Sets the value of [sentiment][crate::model::Entity::sentiment].
333    pub fn set_sentiment<T: std::convert::Into<std::option::Option<crate::model::Sentiment>>>(
334        mut self,
335        v: T,
336    ) -> Self {
337        self.sentiment = v.into();
338        self
339    }
340
341    /// Sets the value of [mentions][crate::model::Entity::mentions].
342    pub fn set_mentions<T, V>(mut self, v: T) -> Self
343    where
344        T: std::iter::IntoIterator<Item = V>,
345        V: std::convert::Into<crate::model::EntityMention>,
346    {
347        use std::iter::Iterator;
348        self.mentions = v.into_iter().map(|i| i.into()).collect();
349        self
350    }
351
352    /// Sets the value of [metadata][crate::model::Entity::metadata].
353    pub fn set_metadata<T, K, V>(mut self, v: T) -> Self
354    where
355        T: std::iter::IntoIterator<Item = (K, V)>,
356        K: std::convert::Into<std::string::String>,
357        V: std::convert::Into<std::string::String>,
358    {
359        use std::iter::Iterator;
360        self.metadata = v.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
361        self
362    }
363}
364
365impl wkt::message::Message for Entity {
366    fn typename() -> &'static str {
367        "type.googleapis.com/google.cloud.language.v2.Entity"
368    }
369}
370
371/// Defines additional types related to [Entity].
372pub mod entity {
373    #[allow(unused_imports)]
374    use super::*;
375
376    /// The type of the entity. The table
377    /// below lists the associated fields for entities that have different
378    /// metadata.
379    #[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)]
380    pub struct Type(i32);
381
382    impl Type {
383        /// Unknown
384        pub const UNKNOWN: Type = Type::new(0);
385
386        /// Person
387        pub const PERSON: Type = Type::new(1);
388
389        /// Location
390        pub const LOCATION: Type = Type::new(2);
391
392        /// Organization
393        pub const ORGANIZATION: Type = Type::new(3);
394
395        /// Event
396        pub const EVENT: Type = Type::new(4);
397
398        /// Artwork
399        pub const WORK_OF_ART: Type = Type::new(5);
400
401        /// Consumer product
402        pub const CONSUMER_GOOD: Type = Type::new(6);
403
404        /// Other types of entities
405        pub const OTHER: Type = Type::new(7);
406
407        /// Phone number
408        ///
409        /// The metadata lists the phone number, formatted according to local
410        /// convention, plus whichever additional elements appear in the text:
411        ///
412        /// * `number` - the actual number, broken down into sections as per local
413        ///   convention
414        /// * `national_prefix` - country code, if detected
415        /// * `area_code` - region or area code, if detected
416        /// * `extension` - phone extension (to be dialed after connection), if
417        ///   detected
418        pub const PHONE_NUMBER: Type = Type::new(9);
419
420        /// Address
421        ///
422        /// The metadata identifies the street number and locality plus whichever
423        /// additional elements appear in the text:
424        ///
425        /// * `street_number` - street number
426        /// * `locality` - city or town
427        /// * `street_name` - street/route name, if detected
428        /// * `postal_code` - postal code, if detected
429        /// * `country` - country, if detected
430        /// * `broad_region` - administrative area, such as the state, if detected
431        /// * `narrow_region` - smaller administrative area, such as county, if
432        ///   detected
433        /// * `sublocality` - used in Asian addresses to demark a district within a
434        ///   city, if detected
435        pub const ADDRESS: Type = Type::new(10);
436
437        /// Date
438        ///
439        /// The metadata identifies the components of the date:
440        ///
441        /// * `year` - four digit year, if detected
442        /// * `month` - two digit month number, if detected
443        /// * `day` - two digit day number, if detected
444        pub const DATE: Type = Type::new(11);
445
446        /// Number
447        ///
448        /// The metadata is the number itself.
449        pub const NUMBER: Type = Type::new(12);
450
451        /// Price
452        ///
453        /// The metadata identifies the `value` and `currency`.
454        pub const PRICE: Type = Type::new(13);
455
456        /// Creates a new Type instance.
457        pub(crate) const fn new(value: i32) -> Self {
458            Self(value)
459        }
460
461        /// Gets the enum value.
462        pub fn value(&self) -> i32 {
463            self.0
464        }
465
466        /// Gets the enum value as a string.
467        pub fn as_str_name(&self) -> std::borrow::Cow<'static, str> {
468            match self.0 {
469                0 => std::borrow::Cow::Borrowed("UNKNOWN"),
470                1 => std::borrow::Cow::Borrowed("PERSON"),
471                2 => std::borrow::Cow::Borrowed("LOCATION"),
472                3 => std::borrow::Cow::Borrowed("ORGANIZATION"),
473                4 => std::borrow::Cow::Borrowed("EVENT"),
474                5 => std::borrow::Cow::Borrowed("WORK_OF_ART"),
475                6 => std::borrow::Cow::Borrowed("CONSUMER_GOOD"),
476                7 => std::borrow::Cow::Borrowed("OTHER"),
477                9 => std::borrow::Cow::Borrowed("PHONE_NUMBER"),
478                10 => std::borrow::Cow::Borrowed("ADDRESS"),
479                11 => std::borrow::Cow::Borrowed("DATE"),
480                12 => std::borrow::Cow::Borrowed("NUMBER"),
481                13 => std::borrow::Cow::Borrowed("PRICE"),
482                _ => std::borrow::Cow::Owned(std::format!("UNKNOWN-VALUE:{}", self.0)),
483            }
484        }
485
486        /// Creates an enum value from the value name.
487        pub fn from_str_name(name: &str) -> std::option::Option<Self> {
488            match name {
489                "UNKNOWN" => std::option::Option::Some(Self::UNKNOWN),
490                "PERSON" => std::option::Option::Some(Self::PERSON),
491                "LOCATION" => std::option::Option::Some(Self::LOCATION),
492                "ORGANIZATION" => std::option::Option::Some(Self::ORGANIZATION),
493                "EVENT" => std::option::Option::Some(Self::EVENT),
494                "WORK_OF_ART" => std::option::Option::Some(Self::WORK_OF_ART),
495                "CONSUMER_GOOD" => std::option::Option::Some(Self::CONSUMER_GOOD),
496                "OTHER" => std::option::Option::Some(Self::OTHER),
497                "PHONE_NUMBER" => std::option::Option::Some(Self::PHONE_NUMBER),
498                "ADDRESS" => std::option::Option::Some(Self::ADDRESS),
499                "DATE" => std::option::Option::Some(Self::DATE),
500                "NUMBER" => std::option::Option::Some(Self::NUMBER),
501                "PRICE" => std::option::Option::Some(Self::PRICE),
502                _ => std::option::Option::None,
503            }
504        }
505    }
506
507    impl std::convert::From<i32> for Type {
508        fn from(value: i32) -> Self {
509            Self::new(value)
510        }
511    }
512
513    impl std::default::Default for Type {
514        fn default() -> Self {
515            Self::new(0)
516        }
517    }
518}
519
520/// Represents the feeling associated with the entire text or entities in
521/// the text.
522#[serde_with::serde_as]
523#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
524#[serde(default, rename_all = "camelCase")]
525#[non_exhaustive]
526pub struct Sentiment {
527    /// A non-negative number in the [0, +inf) range, which represents
528    /// the absolute magnitude of sentiment regardless of score (positive or
529    /// negative).
530    pub magnitude: f32,
531
532    /// Sentiment score between -1.0 (negative sentiment) and 1.0
533    /// (positive sentiment).
534    pub score: f32,
535
536    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
537    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
538}
539
540impl Sentiment {
541    pub fn new() -> Self {
542        std::default::Default::default()
543    }
544
545    /// Sets the value of [magnitude][crate::model::Sentiment::magnitude].
546    pub fn set_magnitude<T: std::convert::Into<f32>>(mut self, v: T) -> Self {
547        self.magnitude = v.into();
548        self
549    }
550
551    /// Sets the value of [score][crate::model::Sentiment::score].
552    pub fn set_score<T: std::convert::Into<f32>>(mut self, v: T) -> Self {
553        self.score = v.into();
554        self
555    }
556}
557
558impl wkt::message::Message for Sentiment {
559    fn typename() -> &'static str {
560        "type.googleapis.com/google.cloud.language.v2.Sentiment"
561    }
562}
563
564/// Represents a mention for an entity in the text. Currently, proper noun
565/// mentions are supported.
566#[serde_with::serde_as]
567#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
568#[serde(default, rename_all = "camelCase")]
569#[non_exhaustive]
570pub struct EntityMention {
571    /// The mention text.
572    #[serde(skip_serializing_if = "std::option::Option::is_none")]
573    pub text: std::option::Option<crate::model::TextSpan>,
574
575    /// The type of the entity mention.
576    #[serde(rename = "type")]
577    pub r#type: crate::model::entity_mention::Type,
578
579    /// For calls to [AnalyzeEntitySentiment][] or if
580    /// [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entity_sentiment]
581    /// is set to true, this field will contain the sentiment expressed for this
582    /// mention of the entity in the provided document.
583    #[serde(skip_serializing_if = "std::option::Option::is_none")]
584    pub sentiment: std::option::Option<crate::model::Sentiment>,
585
586    /// Probability score associated with the entity.
587    ///
588    /// The score shows the probability of the entity mention being the entity
589    /// type. The score is in (0, 1] range.
590    pub probability: f32,
591
592    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
593    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
594}
595
596impl EntityMention {
597    pub fn new() -> Self {
598        std::default::Default::default()
599    }
600
601    /// Sets the value of [text][crate::model::EntityMention::text].
602    pub fn set_text<T: std::convert::Into<std::option::Option<crate::model::TextSpan>>>(
603        mut self,
604        v: T,
605    ) -> Self {
606        self.text = v.into();
607        self
608    }
609
610    /// Sets the value of [r#type][crate::model::EntityMention::type].
611    pub fn set_type<T: std::convert::Into<crate::model::entity_mention::Type>>(
612        mut self,
613        v: T,
614    ) -> Self {
615        self.r#type = v.into();
616        self
617    }
618
619    /// Sets the value of [sentiment][crate::model::EntityMention::sentiment].
620    pub fn set_sentiment<T: std::convert::Into<std::option::Option<crate::model::Sentiment>>>(
621        mut self,
622        v: T,
623    ) -> Self {
624        self.sentiment = v.into();
625        self
626    }
627
628    /// Sets the value of [probability][crate::model::EntityMention::probability].
629    pub fn set_probability<T: std::convert::Into<f32>>(mut self, v: T) -> Self {
630        self.probability = v.into();
631        self
632    }
633}
634
635impl wkt::message::Message for EntityMention {
636    fn typename() -> &'static str {
637        "type.googleapis.com/google.cloud.language.v2.EntityMention"
638    }
639}
640
641/// Defines additional types related to [EntityMention].
642pub mod entity_mention {
643    #[allow(unused_imports)]
644    use super::*;
645
646    /// The supported types of mentions.
647    #[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)]
648    pub struct Type(i32);
649
650    impl Type {
651        /// Unknown
652        pub const TYPE_UNKNOWN: Type = Type::new(0);
653
654        /// Proper name
655        pub const PROPER: Type = Type::new(1);
656
657        /// Common noun (or noun compound)
658        pub const COMMON: Type = Type::new(2);
659
660        /// Creates a new Type instance.
661        pub(crate) const fn new(value: i32) -> Self {
662            Self(value)
663        }
664
665        /// Gets the enum value.
666        pub fn value(&self) -> i32 {
667            self.0
668        }
669
670        /// Gets the enum value as a string.
671        pub fn as_str_name(&self) -> std::borrow::Cow<'static, str> {
672            match self.0 {
673                0 => std::borrow::Cow::Borrowed("TYPE_UNKNOWN"),
674                1 => std::borrow::Cow::Borrowed("PROPER"),
675                2 => std::borrow::Cow::Borrowed("COMMON"),
676                _ => std::borrow::Cow::Owned(std::format!("UNKNOWN-VALUE:{}", self.0)),
677            }
678        }
679
680        /// Creates an enum value from the value name.
681        pub fn from_str_name(name: &str) -> std::option::Option<Self> {
682            match name {
683                "TYPE_UNKNOWN" => std::option::Option::Some(Self::TYPE_UNKNOWN),
684                "PROPER" => std::option::Option::Some(Self::PROPER),
685                "COMMON" => std::option::Option::Some(Self::COMMON),
686                _ => std::option::Option::None,
687            }
688        }
689    }
690
691    impl std::convert::From<i32> for Type {
692        fn from(value: i32) -> Self {
693            Self::new(value)
694        }
695    }
696
697    impl std::default::Default for Type {
698        fn default() -> Self {
699            Self::new(0)
700        }
701    }
702}
703
704/// Represents a text span in the input document.
705#[serde_with::serde_as]
706#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
707#[serde(default, rename_all = "camelCase")]
708#[non_exhaustive]
709pub struct TextSpan {
710    /// The content of the text span, which is a substring of the document.
711    #[serde(skip_serializing_if = "std::string::String::is_empty")]
712    pub content: std::string::String,
713
714    /// The API calculates the beginning offset of the content in the original
715    /// document according to the
716    /// [EncodingType][google.cloud.language.v2.EncodingType] specified in the API
717    /// request.
718    ///
719    /// [google.cloud.language.v2.EncodingType]: crate::model::EncodingType
720    pub begin_offset: i32,
721
722    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
723    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
724}
725
726impl TextSpan {
727    pub fn new() -> Self {
728        std::default::Default::default()
729    }
730
731    /// Sets the value of [content][crate::model::TextSpan::content].
732    pub fn set_content<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
733        self.content = v.into();
734        self
735    }
736
737    /// Sets the value of [begin_offset][crate::model::TextSpan::begin_offset].
738    pub fn set_begin_offset<T: std::convert::Into<i32>>(mut self, v: T) -> Self {
739        self.begin_offset = v.into();
740        self
741    }
742}
743
744impl wkt::message::Message for TextSpan {
745    fn typename() -> &'static str {
746        "type.googleapis.com/google.cloud.language.v2.TextSpan"
747    }
748}
749
750/// Represents a category returned from the text classifier.
751#[serde_with::serde_as]
752#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
753#[serde(default, rename_all = "camelCase")]
754#[non_exhaustive]
755pub struct ClassificationCategory {
756    /// The name of the category representing the document.
757    #[serde(skip_serializing_if = "std::string::String::is_empty")]
758    pub name: std::string::String,
759
760    /// The classifier's confidence of the category. Number represents how certain
761    /// the classifier is that this category represents the given text.
762    pub confidence: f32,
763
764    /// Optional. The classifier's severity of the category. This is only present
765    /// when the ModerateTextRequest.ModelVersion is set to MODEL_VERSION_2, and
766    /// the corresponding category has a severity score.
767    pub severity: f32,
768
769    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
770    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
771}
772
773impl ClassificationCategory {
774    pub fn new() -> Self {
775        std::default::Default::default()
776    }
777
778    /// Sets the value of [name][crate::model::ClassificationCategory::name].
779    pub fn set_name<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
780        self.name = v.into();
781        self
782    }
783
784    /// Sets the value of [confidence][crate::model::ClassificationCategory::confidence].
785    pub fn set_confidence<T: std::convert::Into<f32>>(mut self, v: T) -> Self {
786        self.confidence = v.into();
787        self
788    }
789
790    /// Sets the value of [severity][crate::model::ClassificationCategory::severity].
791    pub fn set_severity<T: std::convert::Into<f32>>(mut self, v: T) -> Self {
792        self.severity = v.into();
793        self
794    }
795}
796
797impl wkt::message::Message for ClassificationCategory {
798    fn typename() -> &'static str {
799        "type.googleapis.com/google.cloud.language.v2.ClassificationCategory"
800    }
801}
802
803/// The sentiment analysis request message.
804#[serde_with::serde_as]
805#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
806#[serde(default, rename_all = "camelCase")]
807#[non_exhaustive]
808pub struct AnalyzeSentimentRequest {
809    /// Required. Input document.
810    #[serde(skip_serializing_if = "std::option::Option::is_none")]
811    pub document: std::option::Option<crate::model::Document>,
812
813    /// The encoding type used by the API to calculate sentence offsets.
814    pub encoding_type: crate::model::EncodingType,
815
816    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
817    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
818}
819
820impl AnalyzeSentimentRequest {
821    pub fn new() -> Self {
822        std::default::Default::default()
823    }
824
825    /// Sets the value of [document][crate::model::AnalyzeSentimentRequest::document].
826    pub fn set_document<T: std::convert::Into<std::option::Option<crate::model::Document>>>(
827        mut self,
828        v: T,
829    ) -> Self {
830        self.document = v.into();
831        self
832    }
833
834    /// Sets the value of [encoding_type][crate::model::AnalyzeSentimentRequest::encoding_type].
835    pub fn set_encoding_type<T: std::convert::Into<crate::model::EncodingType>>(
836        mut self,
837        v: T,
838    ) -> Self {
839        self.encoding_type = v.into();
840        self
841    }
842}
843
844impl wkt::message::Message for AnalyzeSentimentRequest {
845    fn typename() -> &'static str {
846        "type.googleapis.com/google.cloud.language.v2.AnalyzeSentimentRequest"
847    }
848}
849
850/// The sentiment analysis response message.
851#[serde_with::serde_as]
852#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
853#[serde(default, rename_all = "camelCase")]
854#[non_exhaustive]
855pub struct AnalyzeSentimentResponse {
856    /// The overall sentiment of the input document.
857    #[serde(skip_serializing_if = "std::option::Option::is_none")]
858    pub document_sentiment: std::option::Option<crate::model::Sentiment>,
859
860    /// The language of the text, which will be the same as the language specified
861    /// in the request or, if not specified, the automatically-detected language.
862    /// See [Document.language][] field for more details.
863    #[serde(skip_serializing_if = "std::string::String::is_empty")]
864    pub language_code: std::string::String,
865
866    /// The sentiment for all the sentences in the document.
867    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
868    pub sentences: std::vec::Vec<crate::model::Sentence>,
869
870    /// Whether the language is officially supported. The API may still return a
871    /// response when the language is not supported, but it is on a best effort
872    /// basis.
873    pub language_supported: bool,
874
875    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
876    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
877}
878
879impl AnalyzeSentimentResponse {
880    pub fn new() -> Self {
881        std::default::Default::default()
882    }
883
884    /// Sets the value of [document_sentiment][crate::model::AnalyzeSentimentResponse::document_sentiment].
885    pub fn set_document_sentiment<
886        T: std::convert::Into<std::option::Option<crate::model::Sentiment>>,
887    >(
888        mut self,
889        v: T,
890    ) -> Self {
891        self.document_sentiment = v.into();
892        self
893    }
894
895    /// Sets the value of [language_code][crate::model::AnalyzeSentimentResponse::language_code].
896    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
897        self.language_code = v.into();
898        self
899    }
900
901    /// Sets the value of [language_supported][crate::model::AnalyzeSentimentResponse::language_supported].
902    pub fn set_language_supported<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
903        self.language_supported = v.into();
904        self
905    }
906
907    /// Sets the value of [sentences][crate::model::AnalyzeSentimentResponse::sentences].
908    pub fn set_sentences<T, V>(mut self, v: T) -> Self
909    where
910        T: std::iter::IntoIterator<Item = V>,
911        V: std::convert::Into<crate::model::Sentence>,
912    {
913        use std::iter::Iterator;
914        self.sentences = v.into_iter().map(|i| i.into()).collect();
915        self
916    }
917}
918
919impl wkt::message::Message for AnalyzeSentimentResponse {
920    fn typename() -> &'static str {
921        "type.googleapis.com/google.cloud.language.v2.AnalyzeSentimentResponse"
922    }
923}
924
925/// The entity analysis request message.
926#[serde_with::serde_as]
927#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
928#[serde(default, rename_all = "camelCase")]
929#[non_exhaustive]
930pub struct AnalyzeEntitiesRequest {
931    /// Required. Input document.
932    #[serde(skip_serializing_if = "std::option::Option::is_none")]
933    pub document: std::option::Option<crate::model::Document>,
934
935    /// The encoding type used by the API to calculate offsets.
936    pub encoding_type: crate::model::EncodingType,
937
938    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
939    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
940}
941
942impl AnalyzeEntitiesRequest {
943    pub fn new() -> Self {
944        std::default::Default::default()
945    }
946
947    /// Sets the value of [document][crate::model::AnalyzeEntitiesRequest::document].
948    pub fn set_document<T: std::convert::Into<std::option::Option<crate::model::Document>>>(
949        mut self,
950        v: T,
951    ) -> Self {
952        self.document = v.into();
953        self
954    }
955
956    /// Sets the value of [encoding_type][crate::model::AnalyzeEntitiesRequest::encoding_type].
957    pub fn set_encoding_type<T: std::convert::Into<crate::model::EncodingType>>(
958        mut self,
959        v: T,
960    ) -> Self {
961        self.encoding_type = v.into();
962        self
963    }
964}
965
966impl wkt::message::Message for AnalyzeEntitiesRequest {
967    fn typename() -> &'static str {
968        "type.googleapis.com/google.cloud.language.v2.AnalyzeEntitiesRequest"
969    }
970}
971
972/// The entity analysis response message.
973#[serde_with::serde_as]
974#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
975#[serde(default, rename_all = "camelCase")]
976#[non_exhaustive]
977pub struct AnalyzeEntitiesResponse {
978    /// The recognized entities in the input document.
979    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
980    pub entities: std::vec::Vec<crate::model::Entity>,
981
982    /// The language of the text, which will be the same as the language specified
983    /// in the request or, if not specified, the automatically-detected language.
984    /// See [Document.language][] field for more details.
985    #[serde(skip_serializing_if = "std::string::String::is_empty")]
986    pub language_code: std::string::String,
987
988    /// Whether the language is officially supported. The API may still return a
989    /// response when the language is not supported, but it is on a best effort
990    /// basis.
991    pub language_supported: bool,
992
993    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
994    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
995}
996
997impl AnalyzeEntitiesResponse {
998    pub fn new() -> Self {
999        std::default::Default::default()
1000    }
1001
1002    /// Sets the value of [language_code][crate::model::AnalyzeEntitiesResponse::language_code].
1003    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
1004        self.language_code = v.into();
1005        self
1006    }
1007
1008    /// Sets the value of [language_supported][crate::model::AnalyzeEntitiesResponse::language_supported].
1009    pub fn set_language_supported<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
1010        self.language_supported = v.into();
1011        self
1012    }
1013
1014    /// Sets the value of [entities][crate::model::AnalyzeEntitiesResponse::entities].
1015    pub fn set_entities<T, V>(mut self, v: T) -> Self
1016    where
1017        T: std::iter::IntoIterator<Item = V>,
1018        V: std::convert::Into<crate::model::Entity>,
1019    {
1020        use std::iter::Iterator;
1021        self.entities = v.into_iter().map(|i| i.into()).collect();
1022        self
1023    }
1024}
1025
1026impl wkt::message::Message for AnalyzeEntitiesResponse {
1027    fn typename() -> &'static str {
1028        "type.googleapis.com/google.cloud.language.v2.AnalyzeEntitiesResponse"
1029    }
1030}
1031
1032/// The document classification request message.
1033#[serde_with::serde_as]
1034#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
1035#[serde(default, rename_all = "camelCase")]
1036#[non_exhaustive]
1037pub struct ClassifyTextRequest {
1038    /// Required. Input document.
1039    #[serde(skip_serializing_if = "std::option::Option::is_none")]
1040    pub document: std::option::Option<crate::model::Document>,
1041
1042    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
1043    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1044}
1045
1046impl ClassifyTextRequest {
1047    pub fn new() -> Self {
1048        std::default::Default::default()
1049    }
1050
1051    /// Sets the value of [document][crate::model::ClassifyTextRequest::document].
1052    pub fn set_document<T: std::convert::Into<std::option::Option<crate::model::Document>>>(
1053        mut self,
1054        v: T,
1055    ) -> Self {
1056        self.document = v.into();
1057        self
1058    }
1059}
1060
1061impl wkt::message::Message for ClassifyTextRequest {
1062    fn typename() -> &'static str {
1063        "type.googleapis.com/google.cloud.language.v2.ClassifyTextRequest"
1064    }
1065}
1066
1067/// The document classification response message.
1068#[serde_with::serde_as]
1069#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
1070#[serde(default, rename_all = "camelCase")]
1071#[non_exhaustive]
1072pub struct ClassifyTextResponse {
1073    /// Categories representing the input document.
1074    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
1075    pub categories: std::vec::Vec<crate::model::ClassificationCategory>,
1076
1077    /// The language of the text, which will be the same as the language specified
1078    /// in the request or, if not specified, the automatically-detected language.
1079    /// See [Document.language][] field for more details.
1080    #[serde(skip_serializing_if = "std::string::String::is_empty")]
1081    pub language_code: std::string::String,
1082
1083    /// Whether the language is officially supported. The API may still return a
1084    /// response when the language is not supported, but it is on a best effort
1085    /// basis.
1086    pub language_supported: bool,
1087
1088    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
1089    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1090}
1091
1092impl ClassifyTextResponse {
1093    pub fn new() -> Self {
1094        std::default::Default::default()
1095    }
1096
1097    /// Sets the value of [language_code][crate::model::ClassifyTextResponse::language_code].
1098    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
1099        self.language_code = v.into();
1100        self
1101    }
1102
1103    /// Sets the value of [language_supported][crate::model::ClassifyTextResponse::language_supported].
1104    pub fn set_language_supported<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
1105        self.language_supported = v.into();
1106        self
1107    }
1108
1109    /// Sets the value of [categories][crate::model::ClassifyTextResponse::categories].
1110    pub fn set_categories<T, V>(mut self, v: T) -> Self
1111    where
1112        T: std::iter::IntoIterator<Item = V>,
1113        V: std::convert::Into<crate::model::ClassificationCategory>,
1114    {
1115        use std::iter::Iterator;
1116        self.categories = v.into_iter().map(|i| i.into()).collect();
1117        self
1118    }
1119}
1120
1121impl wkt::message::Message for ClassifyTextResponse {
1122    fn typename() -> &'static str {
1123        "type.googleapis.com/google.cloud.language.v2.ClassifyTextResponse"
1124    }
1125}
1126
1127/// The document moderation request message.
1128#[serde_with::serde_as]
1129#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
1130#[serde(default, rename_all = "camelCase")]
1131#[non_exhaustive]
1132pub struct ModerateTextRequest {
1133    /// Required. Input document.
1134    #[serde(skip_serializing_if = "std::option::Option::is_none")]
1135    pub document: std::option::Option<crate::model::Document>,
1136
1137    /// Optional. The model version to use for ModerateText.
1138    pub model_version: crate::model::moderate_text_request::ModelVersion,
1139
1140    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
1141    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1142}
1143
1144impl ModerateTextRequest {
1145    pub fn new() -> Self {
1146        std::default::Default::default()
1147    }
1148
1149    /// Sets the value of [document][crate::model::ModerateTextRequest::document].
1150    pub fn set_document<T: std::convert::Into<std::option::Option<crate::model::Document>>>(
1151        mut self,
1152        v: T,
1153    ) -> Self {
1154        self.document = v.into();
1155        self
1156    }
1157
1158    /// Sets the value of [model_version][crate::model::ModerateTextRequest::model_version].
1159    pub fn set_model_version<
1160        T: std::convert::Into<crate::model::moderate_text_request::ModelVersion>,
1161    >(
1162        mut self,
1163        v: T,
1164    ) -> Self {
1165        self.model_version = v.into();
1166        self
1167    }
1168}
1169
1170impl wkt::message::Message for ModerateTextRequest {
1171    fn typename() -> &'static str {
1172        "type.googleapis.com/google.cloud.language.v2.ModerateTextRequest"
1173    }
1174}
1175
1176/// Defines additional types related to [ModerateTextRequest].
1177pub mod moderate_text_request {
1178    #[allow(unused_imports)]
1179    use super::*;
1180
1181    /// The model version to use for ModerateText.
1182    #[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)]
1183    pub struct ModelVersion(i32);
1184
1185    impl ModelVersion {
1186        /// The default model version.
1187        pub const MODEL_VERSION_UNSPECIFIED: ModelVersion = ModelVersion::new(0);
1188
1189        /// Use the v1 model, this model is used by default when not provided.
1190        /// The v1 model only returns probability (confidence) score for each
1191        /// category.
1192        pub const MODEL_VERSION_1: ModelVersion = ModelVersion::new(1);
1193
1194        /// Use the v2 model.
1195        /// The v2 model only returns probability (confidence) score for each
1196        /// category, and returns severity score for a subset of the categories.
1197        pub const MODEL_VERSION_2: ModelVersion = ModelVersion::new(2);
1198
1199        /// Creates a new ModelVersion instance.
1200        pub(crate) const fn new(value: i32) -> Self {
1201            Self(value)
1202        }
1203
1204        /// Gets the enum value.
1205        pub fn value(&self) -> i32 {
1206            self.0
1207        }
1208
1209        /// Gets the enum value as a string.
1210        pub fn as_str_name(&self) -> std::borrow::Cow<'static, str> {
1211            match self.0 {
1212                0 => std::borrow::Cow::Borrowed("MODEL_VERSION_UNSPECIFIED"),
1213                1 => std::borrow::Cow::Borrowed("MODEL_VERSION_1"),
1214                2 => std::borrow::Cow::Borrowed("MODEL_VERSION_2"),
1215                _ => std::borrow::Cow::Owned(std::format!("UNKNOWN-VALUE:{}", self.0)),
1216            }
1217        }
1218
1219        /// Creates an enum value from the value name.
1220        pub fn from_str_name(name: &str) -> std::option::Option<Self> {
1221            match name {
1222                "MODEL_VERSION_UNSPECIFIED" => {
1223                    std::option::Option::Some(Self::MODEL_VERSION_UNSPECIFIED)
1224                }
1225                "MODEL_VERSION_1" => std::option::Option::Some(Self::MODEL_VERSION_1),
1226                "MODEL_VERSION_2" => std::option::Option::Some(Self::MODEL_VERSION_2),
1227                _ => std::option::Option::None,
1228            }
1229        }
1230    }
1231
1232    impl std::convert::From<i32> for ModelVersion {
1233        fn from(value: i32) -> Self {
1234            Self::new(value)
1235        }
1236    }
1237
1238    impl std::default::Default for ModelVersion {
1239        fn default() -> Self {
1240            Self::new(0)
1241        }
1242    }
1243}
1244
1245/// The document moderation response message.
1246#[serde_with::serde_as]
1247#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
1248#[serde(default, rename_all = "camelCase")]
1249#[non_exhaustive]
1250pub struct ModerateTextResponse {
1251    /// Harmful and sensitive categories representing the input document.
1252    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
1253    pub moderation_categories: std::vec::Vec<crate::model::ClassificationCategory>,
1254
1255    /// The language of the text, which will be the same as the language specified
1256    /// in the request or, if not specified, the automatically-detected language.
1257    /// See [Document.language][] field for more details.
1258    #[serde(skip_serializing_if = "std::string::String::is_empty")]
1259    pub language_code: std::string::String,
1260
1261    /// Whether the language is officially supported. The API may still return a
1262    /// response when the language is not supported, but it is on a best effort
1263    /// basis.
1264    pub language_supported: bool,
1265
1266    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
1267    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1268}
1269
1270impl ModerateTextResponse {
1271    pub fn new() -> Self {
1272        std::default::Default::default()
1273    }
1274
1275    /// Sets the value of [language_code][crate::model::ModerateTextResponse::language_code].
1276    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
1277        self.language_code = v.into();
1278        self
1279    }
1280
1281    /// Sets the value of [language_supported][crate::model::ModerateTextResponse::language_supported].
1282    pub fn set_language_supported<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
1283        self.language_supported = v.into();
1284        self
1285    }
1286
1287    /// Sets the value of [moderation_categories][crate::model::ModerateTextResponse::moderation_categories].
1288    pub fn set_moderation_categories<T, V>(mut self, v: T) -> Self
1289    where
1290        T: std::iter::IntoIterator<Item = V>,
1291        V: std::convert::Into<crate::model::ClassificationCategory>,
1292    {
1293        use std::iter::Iterator;
1294        self.moderation_categories = v.into_iter().map(|i| i.into()).collect();
1295        self
1296    }
1297}
1298
1299impl wkt::message::Message for ModerateTextResponse {
1300    fn typename() -> &'static str {
1301        "type.googleapis.com/google.cloud.language.v2.ModerateTextResponse"
1302    }
1303}
1304
1305/// The request message for the text annotation API, which can perform multiple
1306/// analysis types in one call.
1307#[serde_with::serde_as]
1308#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
1309#[serde(default, rename_all = "camelCase")]
1310#[non_exhaustive]
1311pub struct AnnotateTextRequest {
1312    /// Required. Input document.
1313    #[serde(skip_serializing_if = "std::option::Option::is_none")]
1314    pub document: std::option::Option<crate::model::Document>,
1315
1316    /// Required. The enabled features.
1317    #[serde(skip_serializing_if = "std::option::Option::is_none")]
1318    pub features: std::option::Option<crate::model::annotate_text_request::Features>,
1319
1320    /// The encoding type used by the API to calculate offsets.
1321    pub encoding_type: crate::model::EncodingType,
1322
1323    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
1324    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1325}
1326
1327impl AnnotateTextRequest {
1328    pub fn new() -> Self {
1329        std::default::Default::default()
1330    }
1331
1332    /// Sets the value of [document][crate::model::AnnotateTextRequest::document].
1333    pub fn set_document<T: std::convert::Into<std::option::Option<crate::model::Document>>>(
1334        mut self,
1335        v: T,
1336    ) -> Self {
1337        self.document = v.into();
1338        self
1339    }
1340
1341    /// Sets the value of [features][crate::model::AnnotateTextRequest::features].
1342    pub fn set_features<
1343        T: std::convert::Into<std::option::Option<crate::model::annotate_text_request::Features>>,
1344    >(
1345        mut self,
1346        v: T,
1347    ) -> Self {
1348        self.features = v.into();
1349        self
1350    }
1351
1352    /// Sets the value of [encoding_type][crate::model::AnnotateTextRequest::encoding_type].
1353    pub fn set_encoding_type<T: std::convert::Into<crate::model::EncodingType>>(
1354        mut self,
1355        v: T,
1356    ) -> Self {
1357        self.encoding_type = v.into();
1358        self
1359    }
1360}
1361
1362impl wkt::message::Message for AnnotateTextRequest {
1363    fn typename() -> &'static str {
1364        "type.googleapis.com/google.cloud.language.v2.AnnotateTextRequest"
1365    }
1366}
1367
1368/// Defines additional types related to [AnnotateTextRequest].
1369pub mod annotate_text_request {
1370    #[allow(unused_imports)]
1371    use super::*;
1372
1373    /// All available features.
1374    /// Setting each one to true will enable that specific analysis for the input.
1375    #[serde_with::serde_as]
1376    #[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
1377    #[serde(default, rename_all = "camelCase")]
1378    #[non_exhaustive]
1379    pub struct Features {
1380        /// Optional. Extract entities.
1381        pub extract_entities: bool,
1382
1383        /// Optional. Extract document-level sentiment.
1384        pub extract_document_sentiment: bool,
1385
1386        /// Optional. Classify the full document into categories.
1387        pub classify_text: bool,
1388
1389        /// Optional. Moderate the document for harmful and sensitive categories.
1390        pub moderate_text: bool,
1391
1392        #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
1393        _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1394    }
1395
1396    impl Features {
1397        pub fn new() -> Self {
1398            std::default::Default::default()
1399        }
1400
1401        /// Sets the value of [extract_entities][crate::model::annotate_text_request::Features::extract_entities].
1402        pub fn set_extract_entities<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
1403            self.extract_entities = v.into();
1404            self
1405        }
1406
1407        /// Sets the value of [extract_document_sentiment][crate::model::annotate_text_request::Features::extract_document_sentiment].
1408        pub fn set_extract_document_sentiment<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
1409            self.extract_document_sentiment = v.into();
1410            self
1411        }
1412
1413        /// Sets the value of [classify_text][crate::model::annotate_text_request::Features::classify_text].
1414        pub fn set_classify_text<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
1415            self.classify_text = v.into();
1416            self
1417        }
1418
1419        /// Sets the value of [moderate_text][crate::model::annotate_text_request::Features::moderate_text].
1420        pub fn set_moderate_text<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
1421            self.moderate_text = v.into();
1422            self
1423        }
1424    }
1425
1426    impl wkt::message::Message for Features {
1427        fn typename() -> &'static str {
1428            "type.googleapis.com/google.cloud.language.v2.AnnotateTextRequest.Features"
1429        }
1430    }
1431}
1432
1433/// The text annotations response message.
1434#[serde_with::serde_as]
1435#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
1436#[serde(default, rename_all = "camelCase")]
1437#[non_exhaustive]
1438pub struct AnnotateTextResponse {
1439    /// Sentences in the input document. Populated if the user enables
1440    /// [AnnotateTextRequest.Features.extract_document_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment].
1441    ///
1442    /// [google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment]: crate::model::annotate_text_request::Features::extract_document_sentiment
1443    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
1444    pub sentences: std::vec::Vec<crate::model::Sentence>,
1445
1446    /// Entities, along with their semantic information, in the input document.
1447    /// Populated if the user enables
1448    /// [AnnotateTextRequest.Features.extract_entities][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entities]
1449    /// or
1450    /// [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entity_sentiment].
1451    ///
1452    /// [google.cloud.language.v2.AnnotateTextRequest.Features.extract_entities]: crate::model::annotate_text_request::Features::extract_entities
1453    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
1454    pub entities: std::vec::Vec<crate::model::Entity>,
1455
1456    /// The overall sentiment for the document. Populated if the user enables
1457    /// [AnnotateTextRequest.Features.extract_document_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment].
1458    ///
1459    /// [google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment]: crate::model::annotate_text_request::Features::extract_document_sentiment
1460    #[serde(skip_serializing_if = "std::option::Option::is_none")]
1461    pub document_sentiment: std::option::Option<crate::model::Sentiment>,
1462
1463    /// The language of the text, which will be the same as the language specified
1464    /// in the request or, if not specified, the automatically-detected language.
1465    /// See [Document.language][] field for more details.
1466    #[serde(skip_serializing_if = "std::string::String::is_empty")]
1467    pub language_code: std::string::String,
1468
1469    /// Categories identified in the input document.
1470    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
1471    pub categories: std::vec::Vec<crate::model::ClassificationCategory>,
1472
1473    /// Harmful and sensitive categories identified in the input document.
1474    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
1475    pub moderation_categories: std::vec::Vec<crate::model::ClassificationCategory>,
1476
1477    /// Whether the language is officially supported by all requested features.
1478    /// The API may still return a response when the language is not supported, but
1479    /// it is on a best effort basis.
1480    pub language_supported: bool,
1481
1482    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
1483    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1484}
1485
1486impl AnnotateTextResponse {
1487    pub fn new() -> Self {
1488        std::default::Default::default()
1489    }
1490
1491    /// Sets the value of [document_sentiment][crate::model::AnnotateTextResponse::document_sentiment].
1492    pub fn set_document_sentiment<
1493        T: std::convert::Into<std::option::Option<crate::model::Sentiment>>,
1494    >(
1495        mut self,
1496        v: T,
1497    ) -> Self {
1498        self.document_sentiment = v.into();
1499        self
1500    }
1501
1502    /// Sets the value of [language_code][crate::model::AnnotateTextResponse::language_code].
1503    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
1504        self.language_code = v.into();
1505        self
1506    }
1507
1508    /// Sets the value of [language_supported][crate::model::AnnotateTextResponse::language_supported].
1509    pub fn set_language_supported<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
1510        self.language_supported = v.into();
1511        self
1512    }
1513
1514    /// Sets the value of [sentences][crate::model::AnnotateTextResponse::sentences].
1515    pub fn set_sentences<T, V>(mut self, v: T) -> Self
1516    where
1517        T: std::iter::IntoIterator<Item = V>,
1518        V: std::convert::Into<crate::model::Sentence>,
1519    {
1520        use std::iter::Iterator;
1521        self.sentences = v.into_iter().map(|i| i.into()).collect();
1522        self
1523    }
1524
1525    /// Sets the value of [entities][crate::model::AnnotateTextResponse::entities].
1526    pub fn set_entities<T, V>(mut self, v: T) -> Self
1527    where
1528        T: std::iter::IntoIterator<Item = V>,
1529        V: std::convert::Into<crate::model::Entity>,
1530    {
1531        use std::iter::Iterator;
1532        self.entities = v.into_iter().map(|i| i.into()).collect();
1533        self
1534    }
1535
1536    /// Sets the value of [categories][crate::model::AnnotateTextResponse::categories].
1537    pub fn set_categories<T, V>(mut self, v: T) -> Self
1538    where
1539        T: std::iter::IntoIterator<Item = V>,
1540        V: std::convert::Into<crate::model::ClassificationCategory>,
1541    {
1542        use std::iter::Iterator;
1543        self.categories = v.into_iter().map(|i| i.into()).collect();
1544        self
1545    }
1546
1547    /// Sets the value of [moderation_categories][crate::model::AnnotateTextResponse::moderation_categories].
1548    pub fn set_moderation_categories<T, V>(mut self, v: T) -> Self
1549    where
1550        T: std::iter::IntoIterator<Item = V>,
1551        V: std::convert::Into<crate::model::ClassificationCategory>,
1552    {
1553        use std::iter::Iterator;
1554        self.moderation_categories = v.into_iter().map(|i| i.into()).collect();
1555        self
1556    }
1557}
1558
1559impl wkt::message::Message for AnnotateTextResponse {
1560    fn typename() -> &'static str {
1561        "type.googleapis.com/google.cloud.language.v2.AnnotateTextResponse"
1562    }
1563}
1564
1565/// Represents the text encoding that the caller uses to process the output.
1566/// Providing an `EncodingType` is recommended because the API provides the
1567/// beginning offsets for various outputs, such as tokens and mentions, and
1568/// languages that natively use different text encodings may access offsets
1569/// differently.
1570#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)]
1571pub struct EncodingType(i32);
1572
1573impl EncodingType {
1574    /// If `EncodingType` is not specified, encoding-dependent information (such as
1575    /// `begin_offset`) will be set at `-1`.
1576    pub const NONE: EncodingType = EncodingType::new(0);
1577
1578    /// Encoding-dependent information (such as `begin_offset`) is calculated based
1579    /// on the UTF-8 encoding of the input. C++ and Go are examples of languages
1580    /// that use this encoding natively.
1581    pub const UTF8: EncodingType = EncodingType::new(1);
1582
1583    /// Encoding-dependent information (such as `begin_offset`) is calculated based
1584    /// on the UTF-16 encoding of the input. Java and JavaScript are examples of
1585    /// languages that use this encoding natively.
1586    pub const UTF16: EncodingType = EncodingType::new(2);
1587
1588    /// Encoding-dependent information (such as `begin_offset`) is calculated based
1589    /// on the UTF-32 encoding of the input. Python is an example of a language
1590    /// that uses this encoding natively.
1591    pub const UTF32: EncodingType = EncodingType::new(3);
1592
1593    /// Creates a new EncodingType instance.
1594    pub(crate) const fn new(value: i32) -> Self {
1595        Self(value)
1596    }
1597
1598    /// Gets the enum value.
1599    pub fn value(&self) -> i32 {
1600        self.0
1601    }
1602
1603    /// Gets the enum value as a string.
1604    pub fn as_str_name(&self) -> std::borrow::Cow<'static, str> {
1605        match self.0 {
1606            0 => std::borrow::Cow::Borrowed("NONE"),
1607            1 => std::borrow::Cow::Borrowed("UTF8"),
1608            2 => std::borrow::Cow::Borrowed("UTF16"),
1609            3 => std::borrow::Cow::Borrowed("UTF32"),
1610            _ => std::borrow::Cow::Owned(std::format!("UNKNOWN-VALUE:{}", self.0)),
1611        }
1612    }
1613
1614    /// Creates an enum value from the value name.
1615    pub fn from_str_name(name: &str) -> std::option::Option<Self> {
1616        match name {
1617            "NONE" => std::option::Option::Some(Self::NONE),
1618            "UTF8" => std::option::Option::Some(Self::UTF8),
1619            "UTF16" => std::option::Option::Some(Self::UTF16),
1620            "UTF32" => std::option::Option::Some(Self::UTF32),
1621            _ => std::option::Option::None,
1622        }
1623    }
1624}
1625
1626impl std::convert::From<i32> for EncodingType {
1627    fn from(value: i32) -> Self {
1628        Self::new(value)
1629    }
1630}
1631
1632impl std::default::Default for EncodingType {
1633    fn default() -> Self {
1634        Self::new(0)
1635    }
1636}