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