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#[derive(Clone, Default, PartialEq)]
35#[non_exhaustive]
36pub struct Document {
37    /// Required. If the type is not set or is `TYPE_UNSPECIFIED`,
38    /// returns an `INVALID_ARGUMENT` error.
39    pub r#type: crate::model::document::Type,
40
41    /// Optional. The language of the document (if not specified, the language is
42    /// automatically detected). Both ISO and BCP-47 language codes are
43    /// accepted.\<br\>
44    /// [Language
45    /// Support](https://cloud.google.com/natural-language/docs/languages) lists
46    /// currently supported languages for each API method. If the language (either
47    /// specified by the caller or automatically detected) is not supported by the
48    /// called API method, an `INVALID_ARGUMENT` error is returned.
49    pub language_code: std::string::String,
50
51    /// The source of the document: a string containing the content or a
52    /// Google Cloud Storage URI.
53    pub source: std::option::Option<crate::model::document::Source>,
54
55    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
56}
57
58impl Document {
59    pub fn new() -> Self {
60        std::default::Default::default()
61    }
62
63    /// Sets the value of [r#type][crate::model::Document::type].
64    pub fn set_type<T: std::convert::Into<crate::model::document::Type>>(mut self, v: T) -> Self {
65        self.r#type = v.into();
66        self
67    }
68
69    /// Sets the value of [language_code][crate::model::Document::language_code].
70    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
71        self.language_code = v.into();
72        self
73    }
74
75    /// Sets the value of [source][crate::model::Document::source].
76    ///
77    /// Note that all the setters affecting `source` are mutually
78    /// exclusive.
79    pub fn set_source<
80        T: std::convert::Into<std::option::Option<crate::model::document::Source>>,
81    >(
82        mut self,
83        v: T,
84    ) -> Self {
85        self.source = v.into();
86        self
87    }
88
89    /// The value of [source][crate::model::Document::source]
90    /// if it holds a `Content`, `None` if the field is not set or
91    /// holds a different branch.
92    pub fn content(&self) -> std::option::Option<&std::string::String> {
93        #[allow(unreachable_patterns)]
94        self.source.as_ref().and_then(|v| match v {
95            crate::model::document::Source::Content(v) => std::option::Option::Some(v),
96            _ => std::option::Option::None,
97        })
98    }
99
100    /// Sets the value of [source][crate::model::Document::source]
101    /// to hold a `Content`.
102    ///
103    /// Note that all the setters affecting `source` are
104    /// mutually exclusive.
105    pub fn set_content<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
106        self.source = std::option::Option::Some(crate::model::document::Source::Content(v.into()));
107        self
108    }
109
110    /// The value of [source][crate::model::Document::source]
111    /// if it holds a `GcsContentUri`, `None` if the field is not set or
112    /// holds a different branch.
113    pub fn gcs_content_uri(&self) -> std::option::Option<&std::string::String> {
114        #[allow(unreachable_patterns)]
115        self.source.as_ref().and_then(|v| match v {
116            crate::model::document::Source::GcsContentUri(v) => std::option::Option::Some(v),
117            _ => std::option::Option::None,
118        })
119    }
120
121    /// Sets the value of [source][crate::model::Document::source]
122    /// to hold a `GcsContentUri`.
123    ///
124    /// Note that all the setters affecting `source` are
125    /// mutually exclusive.
126    pub fn set_gcs_content_uri<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
127        self.source =
128            std::option::Option::Some(crate::model::document::Source::GcsContentUri(v.into()));
129        self
130    }
131}
132
133impl wkt::message::Message for Document {
134    fn typename() -> &'static str {
135        "type.googleapis.com/google.cloud.language.v2.Document"
136    }
137}
138
139#[doc(hidden)]
140impl<'de> serde::de::Deserialize<'de> for Document {
141    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
142    where
143        D: serde::Deserializer<'de>,
144    {
145        #[allow(non_camel_case_types)]
146        #[doc(hidden)]
147        #[derive(PartialEq, Eq, Hash)]
148        enum __FieldTag {
149            __type,
150            __content,
151            __gcs_content_uri,
152            __language_code,
153            Unknown(std::string::String),
154        }
155        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
156            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
157            where
158                D: serde::Deserializer<'de>,
159            {
160                struct Visitor;
161                impl<'de> serde::de::Visitor<'de> for Visitor {
162                    type Value = __FieldTag;
163                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
164                        formatter.write_str("a field name for Document")
165                    }
166                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
167                    where
168                        E: serde::de::Error,
169                    {
170                        use std::result::Result::Ok;
171                        use std::string::ToString;
172                        match value {
173                            "type" => Ok(__FieldTag::__type),
174                            "content" => Ok(__FieldTag::__content),
175                            "gcsContentUri" => Ok(__FieldTag::__gcs_content_uri),
176                            "gcs_content_uri" => Ok(__FieldTag::__gcs_content_uri),
177                            "languageCode" => Ok(__FieldTag::__language_code),
178                            "language_code" => Ok(__FieldTag::__language_code),
179                            _ => Ok(__FieldTag::Unknown(value.to_string())),
180                        }
181                    }
182                }
183                deserializer.deserialize_identifier(Visitor)
184            }
185        }
186        struct Visitor;
187        impl<'de> serde::de::Visitor<'de> for Visitor {
188            type Value = Document;
189            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
190                formatter.write_str("struct Document")
191            }
192            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
193            where
194                A: serde::de::MapAccess<'de>,
195            {
196                #[allow(unused_imports)]
197                use serde::de::Error;
198                use std::option::Option::Some;
199                let mut fields = std::collections::HashSet::new();
200                let mut result = Self::Value::new();
201                while let Some(tag) = map.next_key::<__FieldTag>()? {
202                    #[allow(clippy::match_single_binding)]
203                    match tag {
204                        __FieldTag::__type => {
205                            if !fields.insert(__FieldTag::__type) {
206                                return std::result::Result::Err(A::Error::duplicate_field(
207                                    "multiple values for type",
208                                ));
209                            }
210                            result.r#type = map
211                                .next_value::<std::option::Option<crate::model::document::Type>>()?
212                                .unwrap_or_default();
213                        }
214                        __FieldTag::__content => {
215                            if !fields.insert(__FieldTag::__content) {
216                                return std::result::Result::Err(A::Error::duplicate_field(
217                                    "multiple values for content",
218                                ));
219                            }
220                            if result.source.is_some() {
221                                return std::result::Result::Err(A::Error::duplicate_field(
222                                    "multiple values for `source`, a oneof with full ID .google.cloud.language.v2.Document.content, latest field was content",
223                                ));
224                            }
225                            result.source =
226                                std::option::Option::Some(crate::model::document::Source::Content(
227                                    map.next_value::<std::option::Option<std::string::String>>()?
228                                        .unwrap_or_default(),
229                                ));
230                        }
231                        __FieldTag::__gcs_content_uri => {
232                            if !fields.insert(__FieldTag::__gcs_content_uri) {
233                                return std::result::Result::Err(A::Error::duplicate_field(
234                                    "multiple values for gcs_content_uri",
235                                ));
236                            }
237                            if result.source.is_some() {
238                                return std::result::Result::Err(A::Error::duplicate_field(
239                                    "multiple values for `source`, a oneof with full ID .google.cloud.language.v2.Document.gcs_content_uri, latest field was gcsContentUri",
240                                ));
241                            }
242                            result.source = std::option::Option::Some(
243                                crate::model::document::Source::GcsContentUri(
244                                    map.next_value::<std::option::Option<std::string::String>>()?
245                                        .unwrap_or_default(),
246                                ),
247                            );
248                        }
249                        __FieldTag::__language_code => {
250                            if !fields.insert(__FieldTag::__language_code) {
251                                return std::result::Result::Err(A::Error::duplicate_field(
252                                    "multiple values for language_code",
253                                ));
254                            }
255                            result.language_code = map
256                                .next_value::<std::option::Option<std::string::String>>()?
257                                .unwrap_or_default();
258                        }
259                        __FieldTag::Unknown(key) => {
260                            let value = map.next_value::<serde_json::Value>()?;
261                            result._unknown_fields.insert(key, value);
262                        }
263                    }
264                }
265                std::result::Result::Ok(result)
266            }
267        }
268        deserializer.deserialize_any(Visitor)
269    }
270}
271
272#[doc(hidden)]
273impl serde::ser::Serialize for Document {
274    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
275    where
276        S: serde::ser::Serializer,
277    {
278        use serde::ser::SerializeMap;
279        #[allow(unused_imports)]
280        use std::option::Option::Some;
281        let mut state = serializer.serialize_map(std::option::Option::None)?;
282        if !wkt::internal::is_default(&self.r#type) {
283            state.serialize_entry("type", &self.r#type)?;
284        }
285        if let Some(value) = self.content() {
286            state.serialize_entry("content", value)?;
287        }
288        if let Some(value) = self.gcs_content_uri() {
289            state.serialize_entry("gcsContentUri", value)?;
290        }
291        if !self.language_code.is_empty() {
292            state.serialize_entry("languageCode", &self.language_code)?;
293        }
294        if !self._unknown_fields.is_empty() {
295            for (key, value) in self._unknown_fields.iter() {
296                state.serialize_entry(key, &value)?;
297            }
298        }
299        state.end()
300    }
301}
302
303impl std::fmt::Debug for Document {
304    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
305        let mut debug_struct = f.debug_struct("Document");
306        debug_struct.field("r#type", &self.r#type);
307        debug_struct.field("language_code", &self.language_code);
308        debug_struct.field("source", &self.source);
309        if !self._unknown_fields.is_empty() {
310            debug_struct.field("_unknown_fields", &self._unknown_fields);
311        }
312        debug_struct.finish()
313    }
314}
315
316/// Defines additional types related to [Document].
317pub mod document {
318    #[allow(unused_imports)]
319    use super::*;
320
321    /// The document types enum.
322    ///
323    /// # Working with unknown values
324    ///
325    /// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
326    /// additional enum variants at any time. Adding new variants is not considered
327    /// a breaking change. Applications should write their code in anticipation of:
328    ///
329    /// - New values appearing in future releases of the client library, **and**
330    /// - New values received dynamically, without application changes.
331    ///
332    /// Please consult the [Working with enums] section in the user guide for some
333    /// guidelines.
334    ///
335    /// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
336    #[derive(Clone, Debug, PartialEq)]
337    #[non_exhaustive]
338    pub enum Type {
339        /// The content type is not specified.
340        Unspecified,
341        /// Plain text
342        PlainText,
343        /// HTML
344        Html,
345        /// If set, the enum was initialized with an unknown value.
346        ///
347        /// Applications can examine the value using [Type::value] or
348        /// [Type::name].
349        UnknownValue(r#type::UnknownValue),
350    }
351
352    #[doc(hidden)]
353    pub mod r#type {
354        #[allow(unused_imports)]
355        use super::*;
356        #[derive(Clone, Debug, PartialEq)]
357        pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
358    }
359
360    impl Type {
361        /// Gets the enum value.
362        ///
363        /// Returns `None` if the enum contains an unknown value deserialized from
364        /// the string representation of enums.
365        pub fn value(&self) -> std::option::Option<i32> {
366            match self {
367                Self::Unspecified => std::option::Option::Some(0),
368                Self::PlainText => std::option::Option::Some(1),
369                Self::Html => std::option::Option::Some(2),
370                Self::UnknownValue(u) => u.0.value(),
371            }
372        }
373
374        /// Gets the enum value as a string.
375        ///
376        /// Returns `None` if the enum contains an unknown value deserialized from
377        /// the integer representation of enums.
378        pub fn name(&self) -> std::option::Option<&str> {
379            match self {
380                Self::Unspecified => std::option::Option::Some("TYPE_UNSPECIFIED"),
381                Self::PlainText => std::option::Option::Some("PLAIN_TEXT"),
382                Self::Html => std::option::Option::Some("HTML"),
383                Self::UnknownValue(u) => u.0.name(),
384            }
385        }
386    }
387
388    impl std::default::Default for Type {
389        fn default() -> Self {
390            use std::convert::From;
391            Self::from(0)
392        }
393    }
394
395    impl std::fmt::Display for Type {
396        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
397            wkt::internal::display_enum(f, self.name(), self.value())
398        }
399    }
400
401    impl std::convert::From<i32> for Type {
402        fn from(value: i32) -> Self {
403            match value {
404                0 => Self::Unspecified,
405                1 => Self::PlainText,
406                2 => Self::Html,
407                _ => Self::UnknownValue(r#type::UnknownValue(
408                    wkt::internal::UnknownEnumValue::Integer(value),
409                )),
410            }
411        }
412    }
413
414    impl std::convert::From<&str> for Type {
415        fn from(value: &str) -> Self {
416            use std::string::ToString;
417            match value {
418                "TYPE_UNSPECIFIED" => Self::Unspecified,
419                "PLAIN_TEXT" => Self::PlainText,
420                "HTML" => Self::Html,
421                _ => Self::UnknownValue(r#type::UnknownValue(
422                    wkt::internal::UnknownEnumValue::String(value.to_string()),
423                )),
424            }
425        }
426    }
427
428    impl serde::ser::Serialize for Type {
429        fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
430        where
431            S: serde::Serializer,
432        {
433            match self {
434                Self::Unspecified => serializer.serialize_i32(0),
435                Self::PlainText => serializer.serialize_i32(1),
436                Self::Html => serializer.serialize_i32(2),
437                Self::UnknownValue(u) => u.0.serialize(serializer),
438            }
439        }
440    }
441
442    impl<'de> serde::de::Deserialize<'de> for Type {
443        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
444        where
445            D: serde::Deserializer<'de>,
446        {
447            deserializer.deserialize_any(wkt::internal::EnumVisitor::<Type>::new(
448                ".google.cloud.language.v2.Document.Type",
449            ))
450        }
451    }
452
453    /// The source of the document: a string containing the content or a
454    /// Google Cloud Storage URI.
455    #[derive(Clone, Debug, PartialEq)]
456    #[non_exhaustive]
457    pub enum Source {
458        /// The content of the input in string format.
459        /// Cloud audit logging exempt since it is based on user data.
460        Content(std::string::String),
461        /// The Google Cloud Storage URI where the file content is located.
462        /// This URI must be of the form: gs://bucket_name/object_name. For more
463        /// details, see <https://cloud.google.com/storage/docs/reference-uris>.
464        /// NOTE: Cloud Storage object versioning is not supported.
465        GcsContentUri(std::string::String),
466    }
467}
468
469/// Represents a sentence in the input document.
470#[derive(Clone, Default, PartialEq)]
471#[non_exhaustive]
472pub struct Sentence {
473    /// The sentence text.
474    pub text: std::option::Option<crate::model::TextSpan>,
475
476    /// For calls to [AnalyzeSentiment][] or if
477    /// [AnnotateTextRequest.Features.extract_document_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment]
478    /// is set to true, this field will contain the sentiment for the sentence.
479    ///
480    /// [google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment]: crate::model::annotate_text_request::Features::extract_document_sentiment
481    pub sentiment: std::option::Option<crate::model::Sentiment>,
482
483    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
484}
485
486impl Sentence {
487    pub fn new() -> Self {
488        std::default::Default::default()
489    }
490
491    /// Sets the value of [text][crate::model::Sentence::text].
492    pub fn set_text<T>(mut self, v: T) -> Self
493    where
494        T: std::convert::Into<crate::model::TextSpan>,
495    {
496        self.text = std::option::Option::Some(v.into());
497        self
498    }
499
500    /// Sets or clears the value of [text][crate::model::Sentence::text].
501    pub fn set_or_clear_text<T>(mut self, v: std::option::Option<T>) -> Self
502    where
503        T: std::convert::Into<crate::model::TextSpan>,
504    {
505        self.text = v.map(|x| x.into());
506        self
507    }
508
509    /// Sets the value of [sentiment][crate::model::Sentence::sentiment].
510    pub fn set_sentiment<T>(mut self, v: T) -> Self
511    where
512        T: std::convert::Into<crate::model::Sentiment>,
513    {
514        self.sentiment = std::option::Option::Some(v.into());
515        self
516    }
517
518    /// Sets or clears the value of [sentiment][crate::model::Sentence::sentiment].
519    pub fn set_or_clear_sentiment<T>(mut self, v: std::option::Option<T>) -> Self
520    where
521        T: std::convert::Into<crate::model::Sentiment>,
522    {
523        self.sentiment = v.map(|x| x.into());
524        self
525    }
526}
527
528impl wkt::message::Message for Sentence {
529    fn typename() -> &'static str {
530        "type.googleapis.com/google.cloud.language.v2.Sentence"
531    }
532}
533
534#[doc(hidden)]
535impl<'de> serde::de::Deserialize<'de> for Sentence {
536    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
537    where
538        D: serde::Deserializer<'de>,
539    {
540        #[allow(non_camel_case_types)]
541        #[doc(hidden)]
542        #[derive(PartialEq, Eq, Hash)]
543        enum __FieldTag {
544            __text,
545            __sentiment,
546            Unknown(std::string::String),
547        }
548        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
549            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
550            where
551                D: serde::Deserializer<'de>,
552            {
553                struct Visitor;
554                impl<'de> serde::de::Visitor<'de> for Visitor {
555                    type Value = __FieldTag;
556                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
557                        formatter.write_str("a field name for Sentence")
558                    }
559                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
560                    where
561                        E: serde::de::Error,
562                    {
563                        use std::result::Result::Ok;
564                        use std::string::ToString;
565                        match value {
566                            "text" => Ok(__FieldTag::__text),
567                            "sentiment" => Ok(__FieldTag::__sentiment),
568                            _ => Ok(__FieldTag::Unknown(value.to_string())),
569                        }
570                    }
571                }
572                deserializer.deserialize_identifier(Visitor)
573            }
574        }
575        struct Visitor;
576        impl<'de> serde::de::Visitor<'de> for Visitor {
577            type Value = Sentence;
578            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
579                formatter.write_str("struct Sentence")
580            }
581            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
582            where
583                A: serde::de::MapAccess<'de>,
584            {
585                #[allow(unused_imports)]
586                use serde::de::Error;
587                use std::option::Option::Some;
588                let mut fields = std::collections::HashSet::new();
589                let mut result = Self::Value::new();
590                while let Some(tag) = map.next_key::<__FieldTag>()? {
591                    #[allow(clippy::match_single_binding)]
592                    match tag {
593                        __FieldTag::__text => {
594                            if !fields.insert(__FieldTag::__text) {
595                                return std::result::Result::Err(A::Error::duplicate_field(
596                                    "multiple values for text",
597                                ));
598                            }
599                            result.text =
600                                map.next_value::<std::option::Option<crate::model::TextSpan>>()?;
601                        }
602                        __FieldTag::__sentiment => {
603                            if !fields.insert(__FieldTag::__sentiment) {
604                                return std::result::Result::Err(A::Error::duplicate_field(
605                                    "multiple values for sentiment",
606                                ));
607                            }
608                            result.sentiment =
609                                map.next_value::<std::option::Option<crate::model::Sentiment>>()?;
610                        }
611                        __FieldTag::Unknown(key) => {
612                            let value = map.next_value::<serde_json::Value>()?;
613                            result._unknown_fields.insert(key, value);
614                        }
615                    }
616                }
617                std::result::Result::Ok(result)
618            }
619        }
620        deserializer.deserialize_any(Visitor)
621    }
622}
623
624#[doc(hidden)]
625impl serde::ser::Serialize for Sentence {
626    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
627    where
628        S: serde::ser::Serializer,
629    {
630        use serde::ser::SerializeMap;
631        #[allow(unused_imports)]
632        use std::option::Option::Some;
633        let mut state = serializer.serialize_map(std::option::Option::None)?;
634        if self.text.is_some() {
635            state.serialize_entry("text", &self.text)?;
636        }
637        if self.sentiment.is_some() {
638            state.serialize_entry("sentiment", &self.sentiment)?;
639        }
640        if !self._unknown_fields.is_empty() {
641            for (key, value) in self._unknown_fields.iter() {
642                state.serialize_entry(key, &value)?;
643            }
644        }
645        state.end()
646    }
647}
648
649impl std::fmt::Debug for Sentence {
650    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
651        let mut debug_struct = f.debug_struct("Sentence");
652        debug_struct.field("text", &self.text);
653        debug_struct.field("sentiment", &self.sentiment);
654        if !self._unknown_fields.is_empty() {
655            debug_struct.field("_unknown_fields", &self._unknown_fields);
656        }
657        debug_struct.finish()
658    }
659}
660
661/// Represents a phrase in the text that is a known entity, such as
662/// a person, an organization, or location. The API associates information, such
663/// as probability and mentions, with entities.
664#[derive(Clone, Default, PartialEq)]
665#[non_exhaustive]
666pub struct Entity {
667    /// The representative name for the entity.
668    pub name: std::string::String,
669
670    /// The entity type.
671    pub r#type: crate::model::entity::Type,
672
673    /// Metadata associated with the entity.
674    ///
675    /// For the metadata
676    /// associated with other entity types, see the Type table below.
677    pub metadata: std::collections::HashMap<std::string::String, std::string::String>,
678
679    /// The mentions of this entity in the input document. The API currently
680    /// supports proper noun mentions.
681    pub mentions: std::vec::Vec<crate::model::EntityMention>,
682
683    /// For calls to [AnalyzeEntitySentiment][] or if
684    /// [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entity_sentiment]
685    /// is set to true, this field will contain the aggregate sentiment expressed
686    /// for this entity in the provided document.
687    pub sentiment: std::option::Option<crate::model::Sentiment>,
688
689    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
690}
691
692impl Entity {
693    pub fn new() -> Self {
694        std::default::Default::default()
695    }
696
697    /// Sets the value of [name][crate::model::Entity::name].
698    pub fn set_name<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
699        self.name = v.into();
700        self
701    }
702
703    /// Sets the value of [r#type][crate::model::Entity::type].
704    pub fn set_type<T: std::convert::Into<crate::model::entity::Type>>(mut self, v: T) -> Self {
705        self.r#type = v.into();
706        self
707    }
708
709    /// Sets the value of [metadata][crate::model::Entity::metadata].
710    pub fn set_metadata<T, K, V>(mut self, v: T) -> Self
711    where
712        T: std::iter::IntoIterator<Item = (K, V)>,
713        K: std::convert::Into<std::string::String>,
714        V: std::convert::Into<std::string::String>,
715    {
716        use std::iter::Iterator;
717        self.metadata = v.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
718        self
719    }
720
721    /// Sets the value of [mentions][crate::model::Entity::mentions].
722    pub fn set_mentions<T, V>(mut self, v: T) -> Self
723    where
724        T: std::iter::IntoIterator<Item = V>,
725        V: std::convert::Into<crate::model::EntityMention>,
726    {
727        use std::iter::Iterator;
728        self.mentions = v.into_iter().map(|i| i.into()).collect();
729        self
730    }
731
732    /// Sets the value of [sentiment][crate::model::Entity::sentiment].
733    pub fn set_sentiment<T>(mut self, v: T) -> Self
734    where
735        T: std::convert::Into<crate::model::Sentiment>,
736    {
737        self.sentiment = std::option::Option::Some(v.into());
738        self
739    }
740
741    /// Sets or clears the value of [sentiment][crate::model::Entity::sentiment].
742    pub fn set_or_clear_sentiment<T>(mut self, v: std::option::Option<T>) -> Self
743    where
744        T: std::convert::Into<crate::model::Sentiment>,
745    {
746        self.sentiment = v.map(|x| x.into());
747        self
748    }
749}
750
751impl wkt::message::Message for Entity {
752    fn typename() -> &'static str {
753        "type.googleapis.com/google.cloud.language.v2.Entity"
754    }
755}
756
757#[doc(hidden)]
758impl<'de> serde::de::Deserialize<'de> for Entity {
759    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
760    where
761        D: serde::Deserializer<'de>,
762    {
763        #[allow(non_camel_case_types)]
764        #[doc(hidden)]
765        #[derive(PartialEq, Eq, Hash)]
766        enum __FieldTag {
767            __name,
768            __type,
769            __metadata,
770            __mentions,
771            __sentiment,
772            Unknown(std::string::String),
773        }
774        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
775            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
776            where
777                D: serde::Deserializer<'de>,
778            {
779                struct Visitor;
780                impl<'de> serde::de::Visitor<'de> for Visitor {
781                    type Value = __FieldTag;
782                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
783                        formatter.write_str("a field name for Entity")
784                    }
785                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
786                    where
787                        E: serde::de::Error,
788                    {
789                        use std::result::Result::Ok;
790                        use std::string::ToString;
791                        match value {
792                            "name" => Ok(__FieldTag::__name),
793                            "type" => Ok(__FieldTag::__type),
794                            "metadata" => Ok(__FieldTag::__metadata),
795                            "mentions" => Ok(__FieldTag::__mentions),
796                            "sentiment" => Ok(__FieldTag::__sentiment),
797                            _ => Ok(__FieldTag::Unknown(value.to_string())),
798                        }
799                    }
800                }
801                deserializer.deserialize_identifier(Visitor)
802            }
803        }
804        struct Visitor;
805        impl<'de> serde::de::Visitor<'de> for Visitor {
806            type Value = Entity;
807            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
808                formatter.write_str("struct Entity")
809            }
810            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
811            where
812                A: serde::de::MapAccess<'de>,
813            {
814                #[allow(unused_imports)]
815                use serde::de::Error;
816                use std::option::Option::Some;
817                let mut fields = std::collections::HashSet::new();
818                let mut result = Self::Value::new();
819                while let Some(tag) = map.next_key::<__FieldTag>()? {
820                    #[allow(clippy::match_single_binding)]
821                    match tag {
822                        __FieldTag::__name => {
823                            if !fields.insert(__FieldTag::__name) {
824                                return std::result::Result::Err(A::Error::duplicate_field(
825                                    "multiple values for name",
826                                ));
827                            }
828                            result.name = map
829                                .next_value::<std::option::Option<std::string::String>>()?
830                                .unwrap_or_default();
831                        }
832                        __FieldTag::__type => {
833                            if !fields.insert(__FieldTag::__type) {
834                                return std::result::Result::Err(A::Error::duplicate_field(
835                                    "multiple values for type",
836                                ));
837                            }
838                            result.r#type = map
839                                .next_value::<std::option::Option<crate::model::entity::Type>>()?
840                                .unwrap_or_default();
841                        }
842                        __FieldTag::__metadata => {
843                            if !fields.insert(__FieldTag::__metadata) {
844                                return std::result::Result::Err(A::Error::duplicate_field(
845                                    "multiple values for metadata",
846                                ));
847                            }
848                            result.metadata = map
849                                .next_value::<std::option::Option<
850                                    std::collections::HashMap<
851                                        std::string::String,
852                                        std::string::String,
853                                    >,
854                                >>()?
855                                .unwrap_or_default();
856                        }
857                        __FieldTag::__mentions => {
858                            if !fields.insert(__FieldTag::__mentions) {
859                                return std::result::Result::Err(A::Error::duplicate_field(
860                                    "multiple values for mentions",
861                                ));
862                            }
863                            result.mentions = map.next_value::<std::option::Option<std::vec::Vec<crate::model::EntityMention>>>()?.unwrap_or_default();
864                        }
865                        __FieldTag::__sentiment => {
866                            if !fields.insert(__FieldTag::__sentiment) {
867                                return std::result::Result::Err(A::Error::duplicate_field(
868                                    "multiple values for sentiment",
869                                ));
870                            }
871                            result.sentiment =
872                                map.next_value::<std::option::Option<crate::model::Sentiment>>()?;
873                        }
874                        __FieldTag::Unknown(key) => {
875                            let value = map.next_value::<serde_json::Value>()?;
876                            result._unknown_fields.insert(key, value);
877                        }
878                    }
879                }
880                std::result::Result::Ok(result)
881            }
882        }
883        deserializer.deserialize_any(Visitor)
884    }
885}
886
887#[doc(hidden)]
888impl serde::ser::Serialize for Entity {
889    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
890    where
891        S: serde::ser::Serializer,
892    {
893        use serde::ser::SerializeMap;
894        #[allow(unused_imports)]
895        use std::option::Option::Some;
896        let mut state = serializer.serialize_map(std::option::Option::None)?;
897        if !self.name.is_empty() {
898            state.serialize_entry("name", &self.name)?;
899        }
900        if !wkt::internal::is_default(&self.r#type) {
901            state.serialize_entry("type", &self.r#type)?;
902        }
903        if !self.metadata.is_empty() {
904            state.serialize_entry("metadata", &self.metadata)?;
905        }
906        if !self.mentions.is_empty() {
907            state.serialize_entry("mentions", &self.mentions)?;
908        }
909        if self.sentiment.is_some() {
910            state.serialize_entry("sentiment", &self.sentiment)?;
911        }
912        if !self._unknown_fields.is_empty() {
913            for (key, value) in self._unknown_fields.iter() {
914                state.serialize_entry(key, &value)?;
915            }
916        }
917        state.end()
918    }
919}
920
921impl std::fmt::Debug for Entity {
922    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
923        let mut debug_struct = f.debug_struct("Entity");
924        debug_struct.field("name", &self.name);
925        debug_struct.field("r#type", &self.r#type);
926        debug_struct.field("metadata", &self.metadata);
927        debug_struct.field("mentions", &self.mentions);
928        debug_struct.field("sentiment", &self.sentiment);
929        if !self._unknown_fields.is_empty() {
930            debug_struct.field("_unknown_fields", &self._unknown_fields);
931        }
932        debug_struct.finish()
933    }
934}
935
936/// Defines additional types related to [Entity].
937pub mod entity {
938    #[allow(unused_imports)]
939    use super::*;
940
941    /// The type of the entity. The table
942    /// below lists the associated fields for entities that have different
943    /// metadata.
944    ///
945    /// # Working with unknown values
946    ///
947    /// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
948    /// additional enum variants at any time. Adding new variants is not considered
949    /// a breaking change. Applications should write their code in anticipation of:
950    ///
951    /// - New values appearing in future releases of the client library, **and**
952    /// - New values received dynamically, without application changes.
953    ///
954    /// Please consult the [Working with enums] section in the user guide for some
955    /// guidelines.
956    ///
957    /// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
958    #[derive(Clone, Debug, PartialEq)]
959    #[non_exhaustive]
960    pub enum Type {
961        /// Unknown
962        Unknown,
963        /// Person
964        Person,
965        /// Location
966        Location,
967        /// Organization
968        Organization,
969        /// Event
970        Event,
971        /// Artwork
972        WorkOfArt,
973        /// Consumer product
974        ConsumerGood,
975        /// Other types of entities
976        Other,
977        /// Phone number
978        ///
979        /// The metadata lists the phone number, formatted according to local
980        /// convention, plus whichever additional elements appear in the text:
981        ///
982        /// * `number` - the actual number, broken down into sections as per local
983        ///   convention
984        /// * `national_prefix` - country code, if detected
985        /// * `area_code` - region or area code, if detected
986        /// * `extension` - phone extension (to be dialed after connection), if
987        ///   detected
988        PhoneNumber,
989        /// Address
990        ///
991        /// The metadata identifies the street number and locality plus whichever
992        /// additional elements appear in the text:
993        ///
994        /// * `street_number` - street number
995        /// * `locality` - city or town
996        /// * `street_name` - street/route name, if detected
997        /// * `postal_code` - postal code, if detected
998        /// * `country` - country, if detected
999        /// * `broad_region` - administrative area, such as the state, if detected
1000        /// * `narrow_region` - smaller administrative area, such as county, if
1001        ///   detected
1002        /// * `sublocality` - used in Asian addresses to demark a district within a
1003        ///   city, if detected
1004        Address,
1005        /// Date
1006        ///
1007        /// The metadata identifies the components of the date:
1008        ///
1009        /// * `year` - four digit year, if detected
1010        /// * `month` - two digit month number, if detected
1011        /// * `day` - two digit day number, if detected
1012        Date,
1013        /// Number
1014        ///
1015        /// The metadata is the number itself.
1016        Number,
1017        /// Price
1018        ///
1019        /// The metadata identifies the `value` and `currency`.
1020        Price,
1021        /// If set, the enum was initialized with an unknown value.
1022        ///
1023        /// Applications can examine the value using [Type::value] or
1024        /// [Type::name].
1025        UnknownValue(r#type::UnknownValue),
1026    }
1027
1028    #[doc(hidden)]
1029    pub mod r#type {
1030        #[allow(unused_imports)]
1031        use super::*;
1032        #[derive(Clone, Debug, PartialEq)]
1033        pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
1034    }
1035
1036    impl Type {
1037        /// Gets the enum value.
1038        ///
1039        /// Returns `None` if the enum contains an unknown value deserialized from
1040        /// the string representation of enums.
1041        pub fn value(&self) -> std::option::Option<i32> {
1042            match self {
1043                Self::Unknown => std::option::Option::Some(0),
1044                Self::Person => std::option::Option::Some(1),
1045                Self::Location => std::option::Option::Some(2),
1046                Self::Organization => std::option::Option::Some(3),
1047                Self::Event => std::option::Option::Some(4),
1048                Self::WorkOfArt => std::option::Option::Some(5),
1049                Self::ConsumerGood => std::option::Option::Some(6),
1050                Self::Other => std::option::Option::Some(7),
1051                Self::PhoneNumber => std::option::Option::Some(9),
1052                Self::Address => std::option::Option::Some(10),
1053                Self::Date => std::option::Option::Some(11),
1054                Self::Number => std::option::Option::Some(12),
1055                Self::Price => std::option::Option::Some(13),
1056                Self::UnknownValue(u) => u.0.value(),
1057            }
1058        }
1059
1060        /// Gets the enum value as a string.
1061        ///
1062        /// Returns `None` if the enum contains an unknown value deserialized from
1063        /// the integer representation of enums.
1064        pub fn name(&self) -> std::option::Option<&str> {
1065            match self {
1066                Self::Unknown => std::option::Option::Some("UNKNOWN"),
1067                Self::Person => std::option::Option::Some("PERSON"),
1068                Self::Location => std::option::Option::Some("LOCATION"),
1069                Self::Organization => std::option::Option::Some("ORGANIZATION"),
1070                Self::Event => std::option::Option::Some("EVENT"),
1071                Self::WorkOfArt => std::option::Option::Some("WORK_OF_ART"),
1072                Self::ConsumerGood => std::option::Option::Some("CONSUMER_GOOD"),
1073                Self::Other => std::option::Option::Some("OTHER"),
1074                Self::PhoneNumber => std::option::Option::Some("PHONE_NUMBER"),
1075                Self::Address => std::option::Option::Some("ADDRESS"),
1076                Self::Date => std::option::Option::Some("DATE"),
1077                Self::Number => std::option::Option::Some("NUMBER"),
1078                Self::Price => std::option::Option::Some("PRICE"),
1079                Self::UnknownValue(u) => u.0.name(),
1080            }
1081        }
1082    }
1083
1084    impl std::default::Default for Type {
1085        fn default() -> Self {
1086            use std::convert::From;
1087            Self::from(0)
1088        }
1089    }
1090
1091    impl std::fmt::Display for Type {
1092        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
1093            wkt::internal::display_enum(f, self.name(), self.value())
1094        }
1095    }
1096
1097    impl std::convert::From<i32> for Type {
1098        fn from(value: i32) -> Self {
1099            match value {
1100                0 => Self::Unknown,
1101                1 => Self::Person,
1102                2 => Self::Location,
1103                3 => Self::Organization,
1104                4 => Self::Event,
1105                5 => Self::WorkOfArt,
1106                6 => Self::ConsumerGood,
1107                7 => Self::Other,
1108                9 => Self::PhoneNumber,
1109                10 => Self::Address,
1110                11 => Self::Date,
1111                12 => Self::Number,
1112                13 => Self::Price,
1113                _ => Self::UnknownValue(r#type::UnknownValue(
1114                    wkt::internal::UnknownEnumValue::Integer(value),
1115                )),
1116            }
1117        }
1118    }
1119
1120    impl std::convert::From<&str> for Type {
1121        fn from(value: &str) -> Self {
1122            use std::string::ToString;
1123            match value {
1124                "UNKNOWN" => Self::Unknown,
1125                "PERSON" => Self::Person,
1126                "LOCATION" => Self::Location,
1127                "ORGANIZATION" => Self::Organization,
1128                "EVENT" => Self::Event,
1129                "WORK_OF_ART" => Self::WorkOfArt,
1130                "CONSUMER_GOOD" => Self::ConsumerGood,
1131                "OTHER" => Self::Other,
1132                "PHONE_NUMBER" => Self::PhoneNumber,
1133                "ADDRESS" => Self::Address,
1134                "DATE" => Self::Date,
1135                "NUMBER" => Self::Number,
1136                "PRICE" => Self::Price,
1137                _ => Self::UnknownValue(r#type::UnknownValue(
1138                    wkt::internal::UnknownEnumValue::String(value.to_string()),
1139                )),
1140            }
1141        }
1142    }
1143
1144    impl serde::ser::Serialize for Type {
1145        fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
1146        where
1147            S: serde::Serializer,
1148        {
1149            match self {
1150                Self::Unknown => serializer.serialize_i32(0),
1151                Self::Person => serializer.serialize_i32(1),
1152                Self::Location => serializer.serialize_i32(2),
1153                Self::Organization => serializer.serialize_i32(3),
1154                Self::Event => serializer.serialize_i32(4),
1155                Self::WorkOfArt => serializer.serialize_i32(5),
1156                Self::ConsumerGood => serializer.serialize_i32(6),
1157                Self::Other => serializer.serialize_i32(7),
1158                Self::PhoneNumber => serializer.serialize_i32(9),
1159                Self::Address => serializer.serialize_i32(10),
1160                Self::Date => serializer.serialize_i32(11),
1161                Self::Number => serializer.serialize_i32(12),
1162                Self::Price => serializer.serialize_i32(13),
1163                Self::UnknownValue(u) => u.0.serialize(serializer),
1164            }
1165        }
1166    }
1167
1168    impl<'de> serde::de::Deserialize<'de> for Type {
1169        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1170        where
1171            D: serde::Deserializer<'de>,
1172        {
1173            deserializer.deserialize_any(wkt::internal::EnumVisitor::<Type>::new(
1174                ".google.cloud.language.v2.Entity.Type",
1175            ))
1176        }
1177    }
1178}
1179
1180/// Represents the feeling associated with the entire text or entities in
1181/// the text.
1182#[derive(Clone, Default, PartialEq)]
1183#[non_exhaustive]
1184pub struct Sentiment {
1185    /// A non-negative number in the [0, +inf) range, which represents
1186    /// the absolute magnitude of sentiment regardless of score (positive or
1187    /// negative).
1188    pub magnitude: f32,
1189
1190    /// Sentiment score between -1.0 (negative sentiment) and 1.0
1191    /// (positive sentiment).
1192    pub score: f32,
1193
1194    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1195}
1196
1197impl Sentiment {
1198    pub fn new() -> Self {
1199        std::default::Default::default()
1200    }
1201
1202    /// Sets the value of [magnitude][crate::model::Sentiment::magnitude].
1203    pub fn set_magnitude<T: std::convert::Into<f32>>(mut self, v: T) -> Self {
1204        self.magnitude = v.into();
1205        self
1206    }
1207
1208    /// Sets the value of [score][crate::model::Sentiment::score].
1209    pub fn set_score<T: std::convert::Into<f32>>(mut self, v: T) -> Self {
1210        self.score = v.into();
1211        self
1212    }
1213}
1214
1215impl wkt::message::Message for Sentiment {
1216    fn typename() -> &'static str {
1217        "type.googleapis.com/google.cloud.language.v2.Sentiment"
1218    }
1219}
1220
1221#[doc(hidden)]
1222impl<'de> serde::de::Deserialize<'de> for Sentiment {
1223    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1224    where
1225        D: serde::Deserializer<'de>,
1226    {
1227        #[allow(non_camel_case_types)]
1228        #[doc(hidden)]
1229        #[derive(PartialEq, Eq, Hash)]
1230        enum __FieldTag {
1231            __magnitude,
1232            __score,
1233            Unknown(std::string::String),
1234        }
1235        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
1236            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1237            where
1238                D: serde::Deserializer<'de>,
1239            {
1240                struct Visitor;
1241                impl<'de> serde::de::Visitor<'de> for Visitor {
1242                    type Value = __FieldTag;
1243                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
1244                        formatter.write_str("a field name for Sentiment")
1245                    }
1246                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
1247                    where
1248                        E: serde::de::Error,
1249                    {
1250                        use std::result::Result::Ok;
1251                        use std::string::ToString;
1252                        match value {
1253                            "magnitude" => Ok(__FieldTag::__magnitude),
1254                            "score" => Ok(__FieldTag::__score),
1255                            _ => Ok(__FieldTag::Unknown(value.to_string())),
1256                        }
1257                    }
1258                }
1259                deserializer.deserialize_identifier(Visitor)
1260            }
1261        }
1262        struct Visitor;
1263        impl<'de> serde::de::Visitor<'de> for Visitor {
1264            type Value = Sentiment;
1265            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
1266                formatter.write_str("struct Sentiment")
1267            }
1268            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
1269            where
1270                A: serde::de::MapAccess<'de>,
1271            {
1272                #[allow(unused_imports)]
1273                use serde::de::Error;
1274                use std::option::Option::Some;
1275                let mut fields = std::collections::HashSet::new();
1276                let mut result = Self::Value::new();
1277                while let Some(tag) = map.next_key::<__FieldTag>()? {
1278                    #[allow(clippy::match_single_binding)]
1279                    match tag {
1280                        __FieldTag::__magnitude => {
1281                            if !fields.insert(__FieldTag::__magnitude) {
1282                                return std::result::Result::Err(A::Error::duplicate_field(
1283                                    "multiple values for magnitude",
1284                                ));
1285                            }
1286                            struct __With(std::option::Option<f32>);
1287                            impl<'de> serde::de::Deserialize<'de> for __With {
1288                                fn deserialize<D>(
1289                                    deserializer: D,
1290                                ) -> std::result::Result<Self, D::Error>
1291                                where
1292                                    D: serde::de::Deserializer<'de>,
1293                                {
1294                                    serde_with::As::< std::option::Option<wkt::internal::F32> >::deserialize(deserializer).map(__With)
1295                                }
1296                            }
1297                            result.magnitude = map.next_value::<__With>()?.0.unwrap_or_default();
1298                        }
1299                        __FieldTag::__score => {
1300                            if !fields.insert(__FieldTag::__score) {
1301                                return std::result::Result::Err(A::Error::duplicate_field(
1302                                    "multiple values for score",
1303                                ));
1304                            }
1305                            struct __With(std::option::Option<f32>);
1306                            impl<'de> serde::de::Deserialize<'de> for __With {
1307                                fn deserialize<D>(
1308                                    deserializer: D,
1309                                ) -> std::result::Result<Self, D::Error>
1310                                where
1311                                    D: serde::de::Deserializer<'de>,
1312                                {
1313                                    serde_with::As::< std::option::Option<wkt::internal::F32> >::deserialize(deserializer).map(__With)
1314                                }
1315                            }
1316                            result.score = map.next_value::<__With>()?.0.unwrap_or_default();
1317                        }
1318                        __FieldTag::Unknown(key) => {
1319                            let value = map.next_value::<serde_json::Value>()?;
1320                            result._unknown_fields.insert(key, value);
1321                        }
1322                    }
1323                }
1324                std::result::Result::Ok(result)
1325            }
1326        }
1327        deserializer.deserialize_any(Visitor)
1328    }
1329}
1330
1331#[doc(hidden)]
1332impl serde::ser::Serialize for Sentiment {
1333    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
1334    where
1335        S: serde::ser::Serializer,
1336    {
1337        use serde::ser::SerializeMap;
1338        #[allow(unused_imports)]
1339        use std::option::Option::Some;
1340        let mut state = serializer.serialize_map(std::option::Option::None)?;
1341        if !wkt::internal::is_default(&self.magnitude) {
1342            struct __With<'a>(&'a f32);
1343            impl<'a> serde::ser::Serialize for __With<'a> {
1344                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
1345                where
1346                    S: serde::ser::Serializer,
1347                {
1348                    serde_with::As::<wkt::internal::F32>::serialize(self.0, serializer)
1349                }
1350            }
1351            state.serialize_entry("magnitude", &__With(&self.magnitude))?;
1352        }
1353        if !wkt::internal::is_default(&self.score) {
1354            struct __With<'a>(&'a f32);
1355            impl<'a> serde::ser::Serialize for __With<'a> {
1356                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
1357                where
1358                    S: serde::ser::Serializer,
1359                {
1360                    serde_with::As::<wkt::internal::F32>::serialize(self.0, serializer)
1361                }
1362            }
1363            state.serialize_entry("score", &__With(&self.score))?;
1364        }
1365        if !self._unknown_fields.is_empty() {
1366            for (key, value) in self._unknown_fields.iter() {
1367                state.serialize_entry(key, &value)?;
1368            }
1369        }
1370        state.end()
1371    }
1372}
1373
1374impl std::fmt::Debug for Sentiment {
1375    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1376        let mut debug_struct = f.debug_struct("Sentiment");
1377        debug_struct.field("magnitude", &self.magnitude);
1378        debug_struct.field("score", &self.score);
1379        if !self._unknown_fields.is_empty() {
1380            debug_struct.field("_unknown_fields", &self._unknown_fields);
1381        }
1382        debug_struct.finish()
1383    }
1384}
1385
1386/// Represents a mention for an entity in the text. Currently, proper noun
1387/// mentions are supported.
1388#[derive(Clone, Default, PartialEq)]
1389#[non_exhaustive]
1390pub struct EntityMention {
1391    /// The mention text.
1392    pub text: std::option::Option<crate::model::TextSpan>,
1393
1394    /// The type of the entity mention.
1395    pub r#type: crate::model::entity_mention::Type,
1396
1397    /// For calls to [AnalyzeEntitySentiment][] or if
1398    /// [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entity_sentiment]
1399    /// is set to true, this field will contain the sentiment expressed for this
1400    /// mention of the entity in the provided document.
1401    pub sentiment: std::option::Option<crate::model::Sentiment>,
1402
1403    /// Probability score associated with the entity.
1404    ///
1405    /// The score shows the probability of the entity mention being the entity
1406    /// type. The score is in (0, 1] range.
1407    pub probability: f32,
1408
1409    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1410}
1411
1412impl EntityMention {
1413    pub fn new() -> Self {
1414        std::default::Default::default()
1415    }
1416
1417    /// Sets the value of [text][crate::model::EntityMention::text].
1418    pub fn set_text<T>(mut self, v: T) -> Self
1419    where
1420        T: std::convert::Into<crate::model::TextSpan>,
1421    {
1422        self.text = std::option::Option::Some(v.into());
1423        self
1424    }
1425
1426    /// Sets or clears the value of [text][crate::model::EntityMention::text].
1427    pub fn set_or_clear_text<T>(mut self, v: std::option::Option<T>) -> Self
1428    where
1429        T: std::convert::Into<crate::model::TextSpan>,
1430    {
1431        self.text = v.map(|x| x.into());
1432        self
1433    }
1434
1435    /// Sets the value of [r#type][crate::model::EntityMention::type].
1436    pub fn set_type<T: std::convert::Into<crate::model::entity_mention::Type>>(
1437        mut self,
1438        v: T,
1439    ) -> Self {
1440        self.r#type = v.into();
1441        self
1442    }
1443
1444    /// Sets the value of [sentiment][crate::model::EntityMention::sentiment].
1445    pub fn set_sentiment<T>(mut self, v: T) -> Self
1446    where
1447        T: std::convert::Into<crate::model::Sentiment>,
1448    {
1449        self.sentiment = std::option::Option::Some(v.into());
1450        self
1451    }
1452
1453    /// Sets or clears the value of [sentiment][crate::model::EntityMention::sentiment].
1454    pub fn set_or_clear_sentiment<T>(mut self, v: std::option::Option<T>) -> Self
1455    where
1456        T: std::convert::Into<crate::model::Sentiment>,
1457    {
1458        self.sentiment = v.map(|x| x.into());
1459        self
1460    }
1461
1462    /// Sets the value of [probability][crate::model::EntityMention::probability].
1463    pub fn set_probability<T: std::convert::Into<f32>>(mut self, v: T) -> Self {
1464        self.probability = v.into();
1465        self
1466    }
1467}
1468
1469impl wkt::message::Message for EntityMention {
1470    fn typename() -> &'static str {
1471        "type.googleapis.com/google.cloud.language.v2.EntityMention"
1472    }
1473}
1474
1475#[doc(hidden)]
1476impl<'de> serde::de::Deserialize<'de> for EntityMention {
1477    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1478    where
1479        D: serde::Deserializer<'de>,
1480    {
1481        #[allow(non_camel_case_types)]
1482        #[doc(hidden)]
1483        #[derive(PartialEq, Eq, Hash)]
1484        enum __FieldTag {
1485            __text,
1486            __type,
1487            __sentiment,
1488            __probability,
1489            Unknown(std::string::String),
1490        }
1491        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
1492            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1493            where
1494                D: serde::Deserializer<'de>,
1495            {
1496                struct Visitor;
1497                impl<'de> serde::de::Visitor<'de> for Visitor {
1498                    type Value = __FieldTag;
1499                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
1500                        formatter.write_str("a field name for EntityMention")
1501                    }
1502                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
1503                    where
1504                        E: serde::de::Error,
1505                    {
1506                        use std::result::Result::Ok;
1507                        use std::string::ToString;
1508                        match value {
1509                            "text" => Ok(__FieldTag::__text),
1510                            "type" => Ok(__FieldTag::__type),
1511                            "sentiment" => Ok(__FieldTag::__sentiment),
1512                            "probability" => Ok(__FieldTag::__probability),
1513                            _ => Ok(__FieldTag::Unknown(value.to_string())),
1514                        }
1515                    }
1516                }
1517                deserializer.deserialize_identifier(Visitor)
1518            }
1519        }
1520        struct Visitor;
1521        impl<'de> serde::de::Visitor<'de> for Visitor {
1522            type Value = EntityMention;
1523            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
1524                formatter.write_str("struct EntityMention")
1525            }
1526            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
1527            where
1528                A: serde::de::MapAccess<'de>,
1529            {
1530                #[allow(unused_imports)]
1531                use serde::de::Error;
1532                use std::option::Option::Some;
1533                let mut fields = std::collections::HashSet::new();
1534                let mut result = Self::Value::new();
1535                while let Some(tag) = map.next_key::<__FieldTag>()? {
1536                    #[allow(clippy::match_single_binding)]
1537                    match tag {
1538                        __FieldTag::__text => {
1539                            if !fields.insert(__FieldTag::__text) {
1540                                return std::result::Result::Err(A::Error::duplicate_field(
1541                                    "multiple values for text",
1542                                ));
1543                            }
1544                            result.text =
1545                                map.next_value::<std::option::Option<crate::model::TextSpan>>()?;
1546                        }
1547                        __FieldTag::__type => {
1548                            if !fields.insert(__FieldTag::__type) {
1549                                return std::result::Result::Err(A::Error::duplicate_field(
1550                                    "multiple values for type",
1551                                ));
1552                            }
1553                            result.r#type = map.next_value::<std::option::Option<crate::model::entity_mention::Type>>()?.unwrap_or_default();
1554                        }
1555                        __FieldTag::__sentiment => {
1556                            if !fields.insert(__FieldTag::__sentiment) {
1557                                return std::result::Result::Err(A::Error::duplicate_field(
1558                                    "multiple values for sentiment",
1559                                ));
1560                            }
1561                            result.sentiment =
1562                                map.next_value::<std::option::Option<crate::model::Sentiment>>()?;
1563                        }
1564                        __FieldTag::__probability => {
1565                            if !fields.insert(__FieldTag::__probability) {
1566                                return std::result::Result::Err(A::Error::duplicate_field(
1567                                    "multiple values for probability",
1568                                ));
1569                            }
1570                            struct __With(std::option::Option<f32>);
1571                            impl<'de> serde::de::Deserialize<'de> for __With {
1572                                fn deserialize<D>(
1573                                    deserializer: D,
1574                                ) -> std::result::Result<Self, D::Error>
1575                                where
1576                                    D: serde::de::Deserializer<'de>,
1577                                {
1578                                    serde_with::As::< std::option::Option<wkt::internal::F32> >::deserialize(deserializer).map(__With)
1579                                }
1580                            }
1581                            result.probability = map.next_value::<__With>()?.0.unwrap_or_default();
1582                        }
1583                        __FieldTag::Unknown(key) => {
1584                            let value = map.next_value::<serde_json::Value>()?;
1585                            result._unknown_fields.insert(key, value);
1586                        }
1587                    }
1588                }
1589                std::result::Result::Ok(result)
1590            }
1591        }
1592        deserializer.deserialize_any(Visitor)
1593    }
1594}
1595
1596#[doc(hidden)]
1597impl serde::ser::Serialize for EntityMention {
1598    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
1599    where
1600        S: serde::ser::Serializer,
1601    {
1602        use serde::ser::SerializeMap;
1603        #[allow(unused_imports)]
1604        use std::option::Option::Some;
1605        let mut state = serializer.serialize_map(std::option::Option::None)?;
1606        if self.text.is_some() {
1607            state.serialize_entry("text", &self.text)?;
1608        }
1609        if !wkt::internal::is_default(&self.r#type) {
1610            state.serialize_entry("type", &self.r#type)?;
1611        }
1612        if self.sentiment.is_some() {
1613            state.serialize_entry("sentiment", &self.sentiment)?;
1614        }
1615        if !wkt::internal::is_default(&self.probability) {
1616            struct __With<'a>(&'a f32);
1617            impl<'a> serde::ser::Serialize for __With<'a> {
1618                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
1619                where
1620                    S: serde::ser::Serializer,
1621                {
1622                    serde_with::As::<wkt::internal::F32>::serialize(self.0, serializer)
1623                }
1624            }
1625            state.serialize_entry("probability", &__With(&self.probability))?;
1626        }
1627        if !self._unknown_fields.is_empty() {
1628            for (key, value) in self._unknown_fields.iter() {
1629                state.serialize_entry(key, &value)?;
1630            }
1631        }
1632        state.end()
1633    }
1634}
1635
1636impl std::fmt::Debug for EntityMention {
1637    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1638        let mut debug_struct = f.debug_struct("EntityMention");
1639        debug_struct.field("text", &self.text);
1640        debug_struct.field("r#type", &self.r#type);
1641        debug_struct.field("sentiment", &self.sentiment);
1642        debug_struct.field("probability", &self.probability);
1643        if !self._unknown_fields.is_empty() {
1644            debug_struct.field("_unknown_fields", &self._unknown_fields);
1645        }
1646        debug_struct.finish()
1647    }
1648}
1649
1650/// Defines additional types related to [EntityMention].
1651pub mod entity_mention {
1652    #[allow(unused_imports)]
1653    use super::*;
1654
1655    /// The supported types of mentions.
1656    ///
1657    /// # Working with unknown values
1658    ///
1659    /// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
1660    /// additional enum variants at any time. Adding new variants is not considered
1661    /// a breaking change. Applications should write their code in anticipation of:
1662    ///
1663    /// - New values appearing in future releases of the client library, **and**
1664    /// - New values received dynamically, without application changes.
1665    ///
1666    /// Please consult the [Working with enums] section in the user guide for some
1667    /// guidelines.
1668    ///
1669    /// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
1670    #[derive(Clone, Debug, PartialEq)]
1671    #[non_exhaustive]
1672    pub enum Type {
1673        /// Unknown
1674        Unknown,
1675        /// Proper name
1676        Proper,
1677        /// Common noun (or noun compound)
1678        Common,
1679        /// If set, the enum was initialized with an unknown value.
1680        ///
1681        /// Applications can examine the value using [Type::value] or
1682        /// [Type::name].
1683        UnknownValue(r#type::UnknownValue),
1684    }
1685
1686    #[doc(hidden)]
1687    pub mod r#type {
1688        #[allow(unused_imports)]
1689        use super::*;
1690        #[derive(Clone, Debug, PartialEq)]
1691        pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
1692    }
1693
1694    impl Type {
1695        /// Gets the enum value.
1696        ///
1697        /// Returns `None` if the enum contains an unknown value deserialized from
1698        /// the string representation of enums.
1699        pub fn value(&self) -> std::option::Option<i32> {
1700            match self {
1701                Self::Unknown => std::option::Option::Some(0),
1702                Self::Proper => std::option::Option::Some(1),
1703                Self::Common => std::option::Option::Some(2),
1704                Self::UnknownValue(u) => u.0.value(),
1705            }
1706        }
1707
1708        /// Gets the enum value as a string.
1709        ///
1710        /// Returns `None` if the enum contains an unknown value deserialized from
1711        /// the integer representation of enums.
1712        pub fn name(&self) -> std::option::Option<&str> {
1713            match self {
1714                Self::Unknown => std::option::Option::Some("TYPE_UNKNOWN"),
1715                Self::Proper => std::option::Option::Some("PROPER"),
1716                Self::Common => std::option::Option::Some("COMMON"),
1717                Self::UnknownValue(u) => u.0.name(),
1718            }
1719        }
1720    }
1721
1722    impl std::default::Default for Type {
1723        fn default() -> Self {
1724            use std::convert::From;
1725            Self::from(0)
1726        }
1727    }
1728
1729    impl std::fmt::Display for Type {
1730        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
1731            wkt::internal::display_enum(f, self.name(), self.value())
1732        }
1733    }
1734
1735    impl std::convert::From<i32> for Type {
1736        fn from(value: i32) -> Self {
1737            match value {
1738                0 => Self::Unknown,
1739                1 => Self::Proper,
1740                2 => Self::Common,
1741                _ => Self::UnknownValue(r#type::UnknownValue(
1742                    wkt::internal::UnknownEnumValue::Integer(value),
1743                )),
1744            }
1745        }
1746    }
1747
1748    impl std::convert::From<&str> for Type {
1749        fn from(value: &str) -> Self {
1750            use std::string::ToString;
1751            match value {
1752                "TYPE_UNKNOWN" => Self::Unknown,
1753                "PROPER" => Self::Proper,
1754                "COMMON" => Self::Common,
1755                _ => Self::UnknownValue(r#type::UnknownValue(
1756                    wkt::internal::UnknownEnumValue::String(value.to_string()),
1757                )),
1758            }
1759        }
1760    }
1761
1762    impl serde::ser::Serialize for Type {
1763        fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
1764        where
1765            S: serde::Serializer,
1766        {
1767            match self {
1768                Self::Unknown => serializer.serialize_i32(0),
1769                Self::Proper => serializer.serialize_i32(1),
1770                Self::Common => serializer.serialize_i32(2),
1771                Self::UnknownValue(u) => u.0.serialize(serializer),
1772            }
1773        }
1774    }
1775
1776    impl<'de> serde::de::Deserialize<'de> for Type {
1777        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1778        where
1779            D: serde::Deserializer<'de>,
1780        {
1781            deserializer.deserialize_any(wkt::internal::EnumVisitor::<Type>::new(
1782                ".google.cloud.language.v2.EntityMention.Type",
1783            ))
1784        }
1785    }
1786}
1787
1788/// Represents a text span in the input document.
1789#[derive(Clone, Default, PartialEq)]
1790#[non_exhaustive]
1791pub struct TextSpan {
1792    /// The content of the text span, which is a substring of the document.
1793    pub content: std::string::String,
1794
1795    /// The API calculates the beginning offset of the content in the original
1796    /// document according to the
1797    /// [EncodingType][google.cloud.language.v2.EncodingType] specified in the API
1798    /// request.
1799    ///
1800    /// [google.cloud.language.v2.EncodingType]: crate::model::EncodingType
1801    pub begin_offset: i32,
1802
1803    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1804}
1805
1806impl TextSpan {
1807    pub fn new() -> Self {
1808        std::default::Default::default()
1809    }
1810
1811    /// Sets the value of [content][crate::model::TextSpan::content].
1812    pub fn set_content<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
1813        self.content = v.into();
1814        self
1815    }
1816
1817    /// Sets the value of [begin_offset][crate::model::TextSpan::begin_offset].
1818    pub fn set_begin_offset<T: std::convert::Into<i32>>(mut self, v: T) -> Self {
1819        self.begin_offset = v.into();
1820        self
1821    }
1822}
1823
1824impl wkt::message::Message for TextSpan {
1825    fn typename() -> &'static str {
1826        "type.googleapis.com/google.cloud.language.v2.TextSpan"
1827    }
1828}
1829
1830#[doc(hidden)]
1831impl<'de> serde::de::Deserialize<'de> for TextSpan {
1832    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1833    where
1834        D: serde::Deserializer<'de>,
1835    {
1836        #[allow(non_camel_case_types)]
1837        #[doc(hidden)]
1838        #[derive(PartialEq, Eq, Hash)]
1839        enum __FieldTag {
1840            __content,
1841            __begin_offset,
1842            Unknown(std::string::String),
1843        }
1844        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
1845            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1846            where
1847                D: serde::Deserializer<'de>,
1848            {
1849                struct Visitor;
1850                impl<'de> serde::de::Visitor<'de> for Visitor {
1851                    type Value = __FieldTag;
1852                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
1853                        formatter.write_str("a field name for TextSpan")
1854                    }
1855                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
1856                    where
1857                        E: serde::de::Error,
1858                    {
1859                        use std::result::Result::Ok;
1860                        use std::string::ToString;
1861                        match value {
1862                            "content" => Ok(__FieldTag::__content),
1863                            "beginOffset" => Ok(__FieldTag::__begin_offset),
1864                            "begin_offset" => Ok(__FieldTag::__begin_offset),
1865                            _ => Ok(__FieldTag::Unknown(value.to_string())),
1866                        }
1867                    }
1868                }
1869                deserializer.deserialize_identifier(Visitor)
1870            }
1871        }
1872        struct Visitor;
1873        impl<'de> serde::de::Visitor<'de> for Visitor {
1874            type Value = TextSpan;
1875            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
1876                formatter.write_str("struct TextSpan")
1877            }
1878            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
1879            where
1880                A: serde::de::MapAccess<'de>,
1881            {
1882                #[allow(unused_imports)]
1883                use serde::de::Error;
1884                use std::option::Option::Some;
1885                let mut fields = std::collections::HashSet::new();
1886                let mut result = Self::Value::new();
1887                while let Some(tag) = map.next_key::<__FieldTag>()? {
1888                    #[allow(clippy::match_single_binding)]
1889                    match tag {
1890                        __FieldTag::__content => {
1891                            if !fields.insert(__FieldTag::__content) {
1892                                return std::result::Result::Err(A::Error::duplicate_field(
1893                                    "multiple values for content",
1894                                ));
1895                            }
1896                            result.content = map
1897                                .next_value::<std::option::Option<std::string::String>>()?
1898                                .unwrap_or_default();
1899                        }
1900                        __FieldTag::__begin_offset => {
1901                            if !fields.insert(__FieldTag::__begin_offset) {
1902                                return std::result::Result::Err(A::Error::duplicate_field(
1903                                    "multiple values for begin_offset",
1904                                ));
1905                            }
1906                            struct __With(std::option::Option<i32>);
1907                            impl<'de> serde::de::Deserialize<'de> for __With {
1908                                fn deserialize<D>(
1909                                    deserializer: D,
1910                                ) -> std::result::Result<Self, D::Error>
1911                                where
1912                                    D: serde::de::Deserializer<'de>,
1913                                {
1914                                    serde_with::As::< std::option::Option<wkt::internal::I32> >::deserialize(deserializer).map(__With)
1915                                }
1916                            }
1917                            result.begin_offset = map.next_value::<__With>()?.0.unwrap_or_default();
1918                        }
1919                        __FieldTag::Unknown(key) => {
1920                            let value = map.next_value::<serde_json::Value>()?;
1921                            result._unknown_fields.insert(key, value);
1922                        }
1923                    }
1924                }
1925                std::result::Result::Ok(result)
1926            }
1927        }
1928        deserializer.deserialize_any(Visitor)
1929    }
1930}
1931
1932#[doc(hidden)]
1933impl serde::ser::Serialize for TextSpan {
1934    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
1935    where
1936        S: serde::ser::Serializer,
1937    {
1938        use serde::ser::SerializeMap;
1939        #[allow(unused_imports)]
1940        use std::option::Option::Some;
1941        let mut state = serializer.serialize_map(std::option::Option::None)?;
1942        if !self.content.is_empty() {
1943            state.serialize_entry("content", &self.content)?;
1944        }
1945        if !wkt::internal::is_default(&self.begin_offset) {
1946            struct __With<'a>(&'a i32);
1947            impl<'a> serde::ser::Serialize for __With<'a> {
1948                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
1949                where
1950                    S: serde::ser::Serializer,
1951                {
1952                    serde_with::As::<wkt::internal::I32>::serialize(self.0, serializer)
1953                }
1954            }
1955            state.serialize_entry("beginOffset", &__With(&self.begin_offset))?;
1956        }
1957        if !self._unknown_fields.is_empty() {
1958            for (key, value) in self._unknown_fields.iter() {
1959                state.serialize_entry(key, &value)?;
1960            }
1961        }
1962        state.end()
1963    }
1964}
1965
1966impl std::fmt::Debug for TextSpan {
1967    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1968        let mut debug_struct = f.debug_struct("TextSpan");
1969        debug_struct.field("content", &self.content);
1970        debug_struct.field("begin_offset", &self.begin_offset);
1971        if !self._unknown_fields.is_empty() {
1972            debug_struct.field("_unknown_fields", &self._unknown_fields);
1973        }
1974        debug_struct.finish()
1975    }
1976}
1977
1978/// Represents a category returned from the text classifier.
1979#[derive(Clone, Default, PartialEq)]
1980#[non_exhaustive]
1981pub struct ClassificationCategory {
1982    /// The name of the category representing the document.
1983    pub name: std::string::String,
1984
1985    /// The classifier's confidence of the category. Number represents how certain
1986    /// the classifier is that this category represents the given text.
1987    pub confidence: f32,
1988
1989    /// Optional. The classifier's severity of the category. This is only present
1990    /// when the ModerateTextRequest.ModelVersion is set to MODEL_VERSION_2, and
1991    /// the corresponding category has a severity score.
1992    pub severity: f32,
1993
1994    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1995}
1996
1997impl ClassificationCategory {
1998    pub fn new() -> Self {
1999        std::default::Default::default()
2000    }
2001
2002    /// Sets the value of [name][crate::model::ClassificationCategory::name].
2003    pub fn set_name<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
2004        self.name = v.into();
2005        self
2006    }
2007
2008    /// Sets the value of [confidence][crate::model::ClassificationCategory::confidence].
2009    pub fn set_confidence<T: std::convert::Into<f32>>(mut self, v: T) -> Self {
2010        self.confidence = v.into();
2011        self
2012    }
2013
2014    /// Sets the value of [severity][crate::model::ClassificationCategory::severity].
2015    pub fn set_severity<T: std::convert::Into<f32>>(mut self, v: T) -> Self {
2016        self.severity = v.into();
2017        self
2018    }
2019}
2020
2021impl wkt::message::Message for ClassificationCategory {
2022    fn typename() -> &'static str {
2023        "type.googleapis.com/google.cloud.language.v2.ClassificationCategory"
2024    }
2025}
2026
2027#[doc(hidden)]
2028impl<'de> serde::de::Deserialize<'de> for ClassificationCategory {
2029    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
2030    where
2031        D: serde::Deserializer<'de>,
2032    {
2033        #[allow(non_camel_case_types)]
2034        #[doc(hidden)]
2035        #[derive(PartialEq, Eq, Hash)]
2036        enum __FieldTag {
2037            __name,
2038            __confidence,
2039            __severity,
2040            Unknown(std::string::String),
2041        }
2042        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
2043            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
2044            where
2045                D: serde::Deserializer<'de>,
2046            {
2047                struct Visitor;
2048                impl<'de> serde::de::Visitor<'de> for Visitor {
2049                    type Value = __FieldTag;
2050                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
2051                        formatter.write_str("a field name for ClassificationCategory")
2052                    }
2053                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
2054                    where
2055                        E: serde::de::Error,
2056                    {
2057                        use std::result::Result::Ok;
2058                        use std::string::ToString;
2059                        match value {
2060                            "name" => Ok(__FieldTag::__name),
2061                            "confidence" => Ok(__FieldTag::__confidence),
2062                            "severity" => Ok(__FieldTag::__severity),
2063                            _ => Ok(__FieldTag::Unknown(value.to_string())),
2064                        }
2065                    }
2066                }
2067                deserializer.deserialize_identifier(Visitor)
2068            }
2069        }
2070        struct Visitor;
2071        impl<'de> serde::de::Visitor<'de> for Visitor {
2072            type Value = ClassificationCategory;
2073            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
2074                formatter.write_str("struct ClassificationCategory")
2075            }
2076            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
2077            where
2078                A: serde::de::MapAccess<'de>,
2079            {
2080                #[allow(unused_imports)]
2081                use serde::de::Error;
2082                use std::option::Option::Some;
2083                let mut fields = std::collections::HashSet::new();
2084                let mut result = Self::Value::new();
2085                while let Some(tag) = map.next_key::<__FieldTag>()? {
2086                    #[allow(clippy::match_single_binding)]
2087                    match tag {
2088                        __FieldTag::__name => {
2089                            if !fields.insert(__FieldTag::__name) {
2090                                return std::result::Result::Err(A::Error::duplicate_field(
2091                                    "multiple values for name",
2092                                ));
2093                            }
2094                            result.name = map
2095                                .next_value::<std::option::Option<std::string::String>>()?
2096                                .unwrap_or_default();
2097                        }
2098                        __FieldTag::__confidence => {
2099                            if !fields.insert(__FieldTag::__confidence) {
2100                                return std::result::Result::Err(A::Error::duplicate_field(
2101                                    "multiple values for confidence",
2102                                ));
2103                            }
2104                            struct __With(std::option::Option<f32>);
2105                            impl<'de> serde::de::Deserialize<'de> for __With {
2106                                fn deserialize<D>(
2107                                    deserializer: D,
2108                                ) -> std::result::Result<Self, D::Error>
2109                                where
2110                                    D: serde::de::Deserializer<'de>,
2111                                {
2112                                    serde_with::As::< std::option::Option<wkt::internal::F32> >::deserialize(deserializer).map(__With)
2113                                }
2114                            }
2115                            result.confidence = map.next_value::<__With>()?.0.unwrap_or_default();
2116                        }
2117                        __FieldTag::__severity => {
2118                            if !fields.insert(__FieldTag::__severity) {
2119                                return std::result::Result::Err(A::Error::duplicate_field(
2120                                    "multiple values for severity",
2121                                ));
2122                            }
2123                            struct __With(std::option::Option<f32>);
2124                            impl<'de> serde::de::Deserialize<'de> for __With {
2125                                fn deserialize<D>(
2126                                    deserializer: D,
2127                                ) -> std::result::Result<Self, D::Error>
2128                                where
2129                                    D: serde::de::Deserializer<'de>,
2130                                {
2131                                    serde_with::As::< std::option::Option<wkt::internal::F32> >::deserialize(deserializer).map(__With)
2132                                }
2133                            }
2134                            result.severity = map.next_value::<__With>()?.0.unwrap_or_default();
2135                        }
2136                        __FieldTag::Unknown(key) => {
2137                            let value = map.next_value::<serde_json::Value>()?;
2138                            result._unknown_fields.insert(key, value);
2139                        }
2140                    }
2141                }
2142                std::result::Result::Ok(result)
2143            }
2144        }
2145        deserializer.deserialize_any(Visitor)
2146    }
2147}
2148
2149#[doc(hidden)]
2150impl serde::ser::Serialize for ClassificationCategory {
2151    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
2152    where
2153        S: serde::ser::Serializer,
2154    {
2155        use serde::ser::SerializeMap;
2156        #[allow(unused_imports)]
2157        use std::option::Option::Some;
2158        let mut state = serializer.serialize_map(std::option::Option::None)?;
2159        if !self.name.is_empty() {
2160            state.serialize_entry("name", &self.name)?;
2161        }
2162        if !wkt::internal::is_default(&self.confidence) {
2163            struct __With<'a>(&'a f32);
2164            impl<'a> serde::ser::Serialize for __With<'a> {
2165                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
2166                where
2167                    S: serde::ser::Serializer,
2168                {
2169                    serde_with::As::<wkt::internal::F32>::serialize(self.0, serializer)
2170                }
2171            }
2172            state.serialize_entry("confidence", &__With(&self.confidence))?;
2173        }
2174        if !wkt::internal::is_default(&self.severity) {
2175            struct __With<'a>(&'a f32);
2176            impl<'a> serde::ser::Serialize for __With<'a> {
2177                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
2178                where
2179                    S: serde::ser::Serializer,
2180                {
2181                    serde_with::As::<wkt::internal::F32>::serialize(self.0, serializer)
2182                }
2183            }
2184            state.serialize_entry("severity", &__With(&self.severity))?;
2185        }
2186        if !self._unknown_fields.is_empty() {
2187            for (key, value) in self._unknown_fields.iter() {
2188                state.serialize_entry(key, &value)?;
2189            }
2190        }
2191        state.end()
2192    }
2193}
2194
2195impl std::fmt::Debug for ClassificationCategory {
2196    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2197        let mut debug_struct = f.debug_struct("ClassificationCategory");
2198        debug_struct.field("name", &self.name);
2199        debug_struct.field("confidence", &self.confidence);
2200        debug_struct.field("severity", &self.severity);
2201        if !self._unknown_fields.is_empty() {
2202            debug_struct.field("_unknown_fields", &self._unknown_fields);
2203        }
2204        debug_struct.finish()
2205    }
2206}
2207
2208/// The sentiment analysis request message.
2209#[derive(Clone, Default, PartialEq)]
2210#[non_exhaustive]
2211pub struct AnalyzeSentimentRequest {
2212    /// Required. Input document.
2213    pub document: std::option::Option<crate::model::Document>,
2214
2215    /// The encoding type used by the API to calculate sentence offsets.
2216    pub encoding_type: crate::model::EncodingType,
2217
2218    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
2219}
2220
2221impl AnalyzeSentimentRequest {
2222    pub fn new() -> Self {
2223        std::default::Default::default()
2224    }
2225
2226    /// Sets the value of [document][crate::model::AnalyzeSentimentRequest::document].
2227    pub fn set_document<T>(mut self, v: T) -> Self
2228    where
2229        T: std::convert::Into<crate::model::Document>,
2230    {
2231        self.document = std::option::Option::Some(v.into());
2232        self
2233    }
2234
2235    /// Sets or clears the value of [document][crate::model::AnalyzeSentimentRequest::document].
2236    pub fn set_or_clear_document<T>(mut self, v: std::option::Option<T>) -> Self
2237    where
2238        T: std::convert::Into<crate::model::Document>,
2239    {
2240        self.document = v.map(|x| x.into());
2241        self
2242    }
2243
2244    /// Sets the value of [encoding_type][crate::model::AnalyzeSentimentRequest::encoding_type].
2245    pub fn set_encoding_type<T: std::convert::Into<crate::model::EncodingType>>(
2246        mut self,
2247        v: T,
2248    ) -> Self {
2249        self.encoding_type = v.into();
2250        self
2251    }
2252}
2253
2254impl wkt::message::Message for AnalyzeSentimentRequest {
2255    fn typename() -> &'static str {
2256        "type.googleapis.com/google.cloud.language.v2.AnalyzeSentimentRequest"
2257    }
2258}
2259
2260#[doc(hidden)]
2261impl<'de> serde::de::Deserialize<'de> for AnalyzeSentimentRequest {
2262    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
2263    where
2264        D: serde::Deserializer<'de>,
2265    {
2266        #[allow(non_camel_case_types)]
2267        #[doc(hidden)]
2268        #[derive(PartialEq, Eq, Hash)]
2269        enum __FieldTag {
2270            __document,
2271            __encoding_type,
2272            Unknown(std::string::String),
2273        }
2274        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
2275            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
2276            where
2277                D: serde::Deserializer<'de>,
2278            {
2279                struct Visitor;
2280                impl<'de> serde::de::Visitor<'de> for Visitor {
2281                    type Value = __FieldTag;
2282                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
2283                        formatter.write_str("a field name for AnalyzeSentimentRequest")
2284                    }
2285                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
2286                    where
2287                        E: serde::de::Error,
2288                    {
2289                        use std::result::Result::Ok;
2290                        use std::string::ToString;
2291                        match value {
2292                            "document" => Ok(__FieldTag::__document),
2293                            "encodingType" => Ok(__FieldTag::__encoding_type),
2294                            "encoding_type" => Ok(__FieldTag::__encoding_type),
2295                            _ => Ok(__FieldTag::Unknown(value.to_string())),
2296                        }
2297                    }
2298                }
2299                deserializer.deserialize_identifier(Visitor)
2300            }
2301        }
2302        struct Visitor;
2303        impl<'de> serde::de::Visitor<'de> for Visitor {
2304            type Value = AnalyzeSentimentRequest;
2305            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
2306                formatter.write_str("struct AnalyzeSentimentRequest")
2307            }
2308            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
2309            where
2310                A: serde::de::MapAccess<'de>,
2311            {
2312                #[allow(unused_imports)]
2313                use serde::de::Error;
2314                use std::option::Option::Some;
2315                let mut fields = std::collections::HashSet::new();
2316                let mut result = Self::Value::new();
2317                while let Some(tag) = map.next_key::<__FieldTag>()? {
2318                    #[allow(clippy::match_single_binding)]
2319                    match tag {
2320                        __FieldTag::__document => {
2321                            if !fields.insert(__FieldTag::__document) {
2322                                return std::result::Result::Err(A::Error::duplicate_field(
2323                                    "multiple values for document",
2324                                ));
2325                            }
2326                            result.document =
2327                                map.next_value::<std::option::Option<crate::model::Document>>()?;
2328                        }
2329                        __FieldTag::__encoding_type => {
2330                            if !fields.insert(__FieldTag::__encoding_type) {
2331                                return std::result::Result::Err(A::Error::duplicate_field(
2332                                    "multiple values for encoding_type",
2333                                ));
2334                            }
2335                            result.encoding_type = map
2336                                .next_value::<std::option::Option<crate::model::EncodingType>>()?
2337                                .unwrap_or_default();
2338                        }
2339                        __FieldTag::Unknown(key) => {
2340                            let value = map.next_value::<serde_json::Value>()?;
2341                            result._unknown_fields.insert(key, value);
2342                        }
2343                    }
2344                }
2345                std::result::Result::Ok(result)
2346            }
2347        }
2348        deserializer.deserialize_any(Visitor)
2349    }
2350}
2351
2352#[doc(hidden)]
2353impl serde::ser::Serialize for AnalyzeSentimentRequest {
2354    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
2355    where
2356        S: serde::ser::Serializer,
2357    {
2358        use serde::ser::SerializeMap;
2359        #[allow(unused_imports)]
2360        use std::option::Option::Some;
2361        let mut state = serializer.serialize_map(std::option::Option::None)?;
2362        if self.document.is_some() {
2363            state.serialize_entry("document", &self.document)?;
2364        }
2365        if !wkt::internal::is_default(&self.encoding_type) {
2366            state.serialize_entry("encodingType", &self.encoding_type)?;
2367        }
2368        if !self._unknown_fields.is_empty() {
2369            for (key, value) in self._unknown_fields.iter() {
2370                state.serialize_entry(key, &value)?;
2371            }
2372        }
2373        state.end()
2374    }
2375}
2376
2377impl std::fmt::Debug for AnalyzeSentimentRequest {
2378    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2379        let mut debug_struct = f.debug_struct("AnalyzeSentimentRequest");
2380        debug_struct.field("document", &self.document);
2381        debug_struct.field("encoding_type", &self.encoding_type);
2382        if !self._unknown_fields.is_empty() {
2383            debug_struct.field("_unknown_fields", &self._unknown_fields);
2384        }
2385        debug_struct.finish()
2386    }
2387}
2388
2389/// The sentiment analysis response message.
2390#[derive(Clone, Default, PartialEq)]
2391#[non_exhaustive]
2392pub struct AnalyzeSentimentResponse {
2393    /// The overall sentiment of the input document.
2394    pub document_sentiment: std::option::Option<crate::model::Sentiment>,
2395
2396    /// The language of the text, which will be the same as the language specified
2397    /// in the request or, if not specified, the automatically-detected language.
2398    /// See [Document.language][] field for more details.
2399    pub language_code: std::string::String,
2400
2401    /// The sentiment for all the sentences in the document.
2402    pub sentences: std::vec::Vec<crate::model::Sentence>,
2403
2404    /// Whether the language is officially supported. The API may still return a
2405    /// response when the language is not supported, but it is on a best effort
2406    /// basis.
2407    pub language_supported: bool,
2408
2409    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
2410}
2411
2412impl AnalyzeSentimentResponse {
2413    pub fn new() -> Self {
2414        std::default::Default::default()
2415    }
2416
2417    /// Sets the value of [document_sentiment][crate::model::AnalyzeSentimentResponse::document_sentiment].
2418    pub fn set_document_sentiment<T>(mut self, v: T) -> Self
2419    where
2420        T: std::convert::Into<crate::model::Sentiment>,
2421    {
2422        self.document_sentiment = std::option::Option::Some(v.into());
2423        self
2424    }
2425
2426    /// Sets or clears the value of [document_sentiment][crate::model::AnalyzeSentimentResponse::document_sentiment].
2427    pub fn set_or_clear_document_sentiment<T>(mut self, v: std::option::Option<T>) -> Self
2428    where
2429        T: std::convert::Into<crate::model::Sentiment>,
2430    {
2431        self.document_sentiment = v.map(|x| x.into());
2432        self
2433    }
2434
2435    /// Sets the value of [language_code][crate::model::AnalyzeSentimentResponse::language_code].
2436    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
2437        self.language_code = v.into();
2438        self
2439    }
2440
2441    /// Sets the value of [sentences][crate::model::AnalyzeSentimentResponse::sentences].
2442    pub fn set_sentences<T, V>(mut self, v: T) -> Self
2443    where
2444        T: std::iter::IntoIterator<Item = V>,
2445        V: std::convert::Into<crate::model::Sentence>,
2446    {
2447        use std::iter::Iterator;
2448        self.sentences = v.into_iter().map(|i| i.into()).collect();
2449        self
2450    }
2451
2452    /// Sets the value of [language_supported][crate::model::AnalyzeSentimentResponse::language_supported].
2453    pub fn set_language_supported<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
2454        self.language_supported = v.into();
2455        self
2456    }
2457}
2458
2459impl wkt::message::Message for AnalyzeSentimentResponse {
2460    fn typename() -> &'static str {
2461        "type.googleapis.com/google.cloud.language.v2.AnalyzeSentimentResponse"
2462    }
2463}
2464
2465#[doc(hidden)]
2466impl<'de> serde::de::Deserialize<'de> for AnalyzeSentimentResponse {
2467    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
2468    where
2469        D: serde::Deserializer<'de>,
2470    {
2471        #[allow(non_camel_case_types)]
2472        #[doc(hidden)]
2473        #[derive(PartialEq, Eq, Hash)]
2474        enum __FieldTag {
2475            __document_sentiment,
2476            __language_code,
2477            __sentences,
2478            __language_supported,
2479            Unknown(std::string::String),
2480        }
2481        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
2482            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
2483            where
2484                D: serde::Deserializer<'de>,
2485            {
2486                struct Visitor;
2487                impl<'de> serde::de::Visitor<'de> for Visitor {
2488                    type Value = __FieldTag;
2489                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
2490                        formatter.write_str("a field name for AnalyzeSentimentResponse")
2491                    }
2492                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
2493                    where
2494                        E: serde::de::Error,
2495                    {
2496                        use std::result::Result::Ok;
2497                        use std::string::ToString;
2498                        match value {
2499                            "documentSentiment" => Ok(__FieldTag::__document_sentiment),
2500                            "document_sentiment" => Ok(__FieldTag::__document_sentiment),
2501                            "languageCode" => Ok(__FieldTag::__language_code),
2502                            "language_code" => Ok(__FieldTag::__language_code),
2503                            "sentences" => Ok(__FieldTag::__sentences),
2504                            "languageSupported" => Ok(__FieldTag::__language_supported),
2505                            "language_supported" => Ok(__FieldTag::__language_supported),
2506                            _ => Ok(__FieldTag::Unknown(value.to_string())),
2507                        }
2508                    }
2509                }
2510                deserializer.deserialize_identifier(Visitor)
2511            }
2512        }
2513        struct Visitor;
2514        impl<'de> serde::de::Visitor<'de> for Visitor {
2515            type Value = AnalyzeSentimentResponse;
2516            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
2517                formatter.write_str("struct AnalyzeSentimentResponse")
2518            }
2519            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
2520            where
2521                A: serde::de::MapAccess<'de>,
2522            {
2523                #[allow(unused_imports)]
2524                use serde::de::Error;
2525                use std::option::Option::Some;
2526                let mut fields = std::collections::HashSet::new();
2527                let mut result = Self::Value::new();
2528                while let Some(tag) = map.next_key::<__FieldTag>()? {
2529                    #[allow(clippy::match_single_binding)]
2530                    match tag {
2531                        __FieldTag::__document_sentiment => {
2532                            if !fields.insert(__FieldTag::__document_sentiment) {
2533                                return std::result::Result::Err(A::Error::duplicate_field(
2534                                    "multiple values for document_sentiment",
2535                                ));
2536                            }
2537                            result.document_sentiment =
2538                                map.next_value::<std::option::Option<crate::model::Sentiment>>()?;
2539                        }
2540                        __FieldTag::__language_code => {
2541                            if !fields.insert(__FieldTag::__language_code) {
2542                                return std::result::Result::Err(A::Error::duplicate_field(
2543                                    "multiple values for language_code",
2544                                ));
2545                            }
2546                            result.language_code = map
2547                                .next_value::<std::option::Option<std::string::String>>()?
2548                                .unwrap_or_default();
2549                        }
2550                        __FieldTag::__sentences => {
2551                            if !fields.insert(__FieldTag::__sentences) {
2552                                return std::result::Result::Err(A::Error::duplicate_field(
2553                                    "multiple values for sentences",
2554                                ));
2555                            }
2556                            result.sentences = map.next_value::<std::option::Option<std::vec::Vec<crate::model::Sentence>>>()?.unwrap_or_default();
2557                        }
2558                        __FieldTag::__language_supported => {
2559                            if !fields.insert(__FieldTag::__language_supported) {
2560                                return std::result::Result::Err(A::Error::duplicate_field(
2561                                    "multiple values for language_supported",
2562                                ));
2563                            }
2564                            result.language_supported = map
2565                                .next_value::<std::option::Option<bool>>()?
2566                                .unwrap_or_default();
2567                        }
2568                        __FieldTag::Unknown(key) => {
2569                            let value = map.next_value::<serde_json::Value>()?;
2570                            result._unknown_fields.insert(key, value);
2571                        }
2572                    }
2573                }
2574                std::result::Result::Ok(result)
2575            }
2576        }
2577        deserializer.deserialize_any(Visitor)
2578    }
2579}
2580
2581#[doc(hidden)]
2582impl serde::ser::Serialize for AnalyzeSentimentResponse {
2583    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
2584    where
2585        S: serde::ser::Serializer,
2586    {
2587        use serde::ser::SerializeMap;
2588        #[allow(unused_imports)]
2589        use std::option::Option::Some;
2590        let mut state = serializer.serialize_map(std::option::Option::None)?;
2591        if self.document_sentiment.is_some() {
2592            state.serialize_entry("documentSentiment", &self.document_sentiment)?;
2593        }
2594        if !self.language_code.is_empty() {
2595            state.serialize_entry("languageCode", &self.language_code)?;
2596        }
2597        if !self.sentences.is_empty() {
2598            state.serialize_entry("sentences", &self.sentences)?;
2599        }
2600        if !wkt::internal::is_default(&self.language_supported) {
2601            state.serialize_entry("languageSupported", &self.language_supported)?;
2602        }
2603        if !self._unknown_fields.is_empty() {
2604            for (key, value) in self._unknown_fields.iter() {
2605                state.serialize_entry(key, &value)?;
2606            }
2607        }
2608        state.end()
2609    }
2610}
2611
2612impl std::fmt::Debug for AnalyzeSentimentResponse {
2613    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2614        let mut debug_struct = f.debug_struct("AnalyzeSentimentResponse");
2615        debug_struct.field("document_sentiment", &self.document_sentiment);
2616        debug_struct.field("language_code", &self.language_code);
2617        debug_struct.field("sentences", &self.sentences);
2618        debug_struct.field("language_supported", &self.language_supported);
2619        if !self._unknown_fields.is_empty() {
2620            debug_struct.field("_unknown_fields", &self._unknown_fields);
2621        }
2622        debug_struct.finish()
2623    }
2624}
2625
2626/// The entity analysis request message.
2627#[derive(Clone, Default, PartialEq)]
2628#[non_exhaustive]
2629pub struct AnalyzeEntitiesRequest {
2630    /// Required. Input document.
2631    pub document: std::option::Option<crate::model::Document>,
2632
2633    /// The encoding type used by the API to calculate offsets.
2634    pub encoding_type: crate::model::EncodingType,
2635
2636    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
2637}
2638
2639impl AnalyzeEntitiesRequest {
2640    pub fn new() -> Self {
2641        std::default::Default::default()
2642    }
2643
2644    /// Sets the value of [document][crate::model::AnalyzeEntitiesRequest::document].
2645    pub fn set_document<T>(mut self, v: T) -> Self
2646    where
2647        T: std::convert::Into<crate::model::Document>,
2648    {
2649        self.document = std::option::Option::Some(v.into());
2650        self
2651    }
2652
2653    /// Sets or clears the value of [document][crate::model::AnalyzeEntitiesRequest::document].
2654    pub fn set_or_clear_document<T>(mut self, v: std::option::Option<T>) -> Self
2655    where
2656        T: std::convert::Into<crate::model::Document>,
2657    {
2658        self.document = v.map(|x| x.into());
2659        self
2660    }
2661
2662    /// Sets the value of [encoding_type][crate::model::AnalyzeEntitiesRequest::encoding_type].
2663    pub fn set_encoding_type<T: std::convert::Into<crate::model::EncodingType>>(
2664        mut self,
2665        v: T,
2666    ) -> Self {
2667        self.encoding_type = v.into();
2668        self
2669    }
2670}
2671
2672impl wkt::message::Message for AnalyzeEntitiesRequest {
2673    fn typename() -> &'static str {
2674        "type.googleapis.com/google.cloud.language.v2.AnalyzeEntitiesRequest"
2675    }
2676}
2677
2678#[doc(hidden)]
2679impl<'de> serde::de::Deserialize<'de> for AnalyzeEntitiesRequest {
2680    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
2681    where
2682        D: serde::Deserializer<'de>,
2683    {
2684        #[allow(non_camel_case_types)]
2685        #[doc(hidden)]
2686        #[derive(PartialEq, Eq, Hash)]
2687        enum __FieldTag {
2688            __document,
2689            __encoding_type,
2690            Unknown(std::string::String),
2691        }
2692        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
2693            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
2694            where
2695                D: serde::Deserializer<'de>,
2696            {
2697                struct Visitor;
2698                impl<'de> serde::de::Visitor<'de> for Visitor {
2699                    type Value = __FieldTag;
2700                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
2701                        formatter.write_str("a field name for AnalyzeEntitiesRequest")
2702                    }
2703                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
2704                    where
2705                        E: serde::de::Error,
2706                    {
2707                        use std::result::Result::Ok;
2708                        use std::string::ToString;
2709                        match value {
2710                            "document" => Ok(__FieldTag::__document),
2711                            "encodingType" => Ok(__FieldTag::__encoding_type),
2712                            "encoding_type" => Ok(__FieldTag::__encoding_type),
2713                            _ => Ok(__FieldTag::Unknown(value.to_string())),
2714                        }
2715                    }
2716                }
2717                deserializer.deserialize_identifier(Visitor)
2718            }
2719        }
2720        struct Visitor;
2721        impl<'de> serde::de::Visitor<'de> for Visitor {
2722            type Value = AnalyzeEntitiesRequest;
2723            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
2724                formatter.write_str("struct AnalyzeEntitiesRequest")
2725            }
2726            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
2727            where
2728                A: serde::de::MapAccess<'de>,
2729            {
2730                #[allow(unused_imports)]
2731                use serde::de::Error;
2732                use std::option::Option::Some;
2733                let mut fields = std::collections::HashSet::new();
2734                let mut result = Self::Value::new();
2735                while let Some(tag) = map.next_key::<__FieldTag>()? {
2736                    #[allow(clippy::match_single_binding)]
2737                    match tag {
2738                        __FieldTag::__document => {
2739                            if !fields.insert(__FieldTag::__document) {
2740                                return std::result::Result::Err(A::Error::duplicate_field(
2741                                    "multiple values for document",
2742                                ));
2743                            }
2744                            result.document =
2745                                map.next_value::<std::option::Option<crate::model::Document>>()?;
2746                        }
2747                        __FieldTag::__encoding_type => {
2748                            if !fields.insert(__FieldTag::__encoding_type) {
2749                                return std::result::Result::Err(A::Error::duplicate_field(
2750                                    "multiple values for encoding_type",
2751                                ));
2752                            }
2753                            result.encoding_type = map
2754                                .next_value::<std::option::Option<crate::model::EncodingType>>()?
2755                                .unwrap_or_default();
2756                        }
2757                        __FieldTag::Unknown(key) => {
2758                            let value = map.next_value::<serde_json::Value>()?;
2759                            result._unknown_fields.insert(key, value);
2760                        }
2761                    }
2762                }
2763                std::result::Result::Ok(result)
2764            }
2765        }
2766        deserializer.deserialize_any(Visitor)
2767    }
2768}
2769
2770#[doc(hidden)]
2771impl serde::ser::Serialize for AnalyzeEntitiesRequest {
2772    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
2773    where
2774        S: serde::ser::Serializer,
2775    {
2776        use serde::ser::SerializeMap;
2777        #[allow(unused_imports)]
2778        use std::option::Option::Some;
2779        let mut state = serializer.serialize_map(std::option::Option::None)?;
2780        if self.document.is_some() {
2781            state.serialize_entry("document", &self.document)?;
2782        }
2783        if !wkt::internal::is_default(&self.encoding_type) {
2784            state.serialize_entry("encodingType", &self.encoding_type)?;
2785        }
2786        if !self._unknown_fields.is_empty() {
2787            for (key, value) in self._unknown_fields.iter() {
2788                state.serialize_entry(key, &value)?;
2789            }
2790        }
2791        state.end()
2792    }
2793}
2794
2795impl std::fmt::Debug for AnalyzeEntitiesRequest {
2796    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2797        let mut debug_struct = f.debug_struct("AnalyzeEntitiesRequest");
2798        debug_struct.field("document", &self.document);
2799        debug_struct.field("encoding_type", &self.encoding_type);
2800        if !self._unknown_fields.is_empty() {
2801            debug_struct.field("_unknown_fields", &self._unknown_fields);
2802        }
2803        debug_struct.finish()
2804    }
2805}
2806
2807/// The entity analysis response message.
2808#[derive(Clone, Default, PartialEq)]
2809#[non_exhaustive]
2810pub struct AnalyzeEntitiesResponse {
2811    /// The recognized entities in the input document.
2812    pub entities: std::vec::Vec<crate::model::Entity>,
2813
2814    /// The language of the text, which will be the same as the language specified
2815    /// in the request or, if not specified, the automatically-detected language.
2816    /// See [Document.language][] field for more details.
2817    pub language_code: std::string::String,
2818
2819    /// Whether the language is officially supported. The API may still return a
2820    /// response when the language is not supported, but it is on a best effort
2821    /// basis.
2822    pub language_supported: bool,
2823
2824    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
2825}
2826
2827impl AnalyzeEntitiesResponse {
2828    pub fn new() -> Self {
2829        std::default::Default::default()
2830    }
2831
2832    /// Sets the value of [entities][crate::model::AnalyzeEntitiesResponse::entities].
2833    pub fn set_entities<T, V>(mut self, v: T) -> Self
2834    where
2835        T: std::iter::IntoIterator<Item = V>,
2836        V: std::convert::Into<crate::model::Entity>,
2837    {
2838        use std::iter::Iterator;
2839        self.entities = v.into_iter().map(|i| i.into()).collect();
2840        self
2841    }
2842
2843    /// Sets the value of [language_code][crate::model::AnalyzeEntitiesResponse::language_code].
2844    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
2845        self.language_code = v.into();
2846        self
2847    }
2848
2849    /// Sets the value of [language_supported][crate::model::AnalyzeEntitiesResponse::language_supported].
2850    pub fn set_language_supported<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
2851        self.language_supported = v.into();
2852        self
2853    }
2854}
2855
2856impl wkt::message::Message for AnalyzeEntitiesResponse {
2857    fn typename() -> &'static str {
2858        "type.googleapis.com/google.cloud.language.v2.AnalyzeEntitiesResponse"
2859    }
2860}
2861
2862#[doc(hidden)]
2863impl<'de> serde::de::Deserialize<'de> for AnalyzeEntitiesResponse {
2864    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
2865    where
2866        D: serde::Deserializer<'de>,
2867    {
2868        #[allow(non_camel_case_types)]
2869        #[doc(hidden)]
2870        #[derive(PartialEq, Eq, Hash)]
2871        enum __FieldTag {
2872            __entities,
2873            __language_code,
2874            __language_supported,
2875            Unknown(std::string::String),
2876        }
2877        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
2878            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
2879            where
2880                D: serde::Deserializer<'de>,
2881            {
2882                struct Visitor;
2883                impl<'de> serde::de::Visitor<'de> for Visitor {
2884                    type Value = __FieldTag;
2885                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
2886                        formatter.write_str("a field name for AnalyzeEntitiesResponse")
2887                    }
2888                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
2889                    where
2890                        E: serde::de::Error,
2891                    {
2892                        use std::result::Result::Ok;
2893                        use std::string::ToString;
2894                        match value {
2895                            "entities" => Ok(__FieldTag::__entities),
2896                            "languageCode" => Ok(__FieldTag::__language_code),
2897                            "language_code" => Ok(__FieldTag::__language_code),
2898                            "languageSupported" => Ok(__FieldTag::__language_supported),
2899                            "language_supported" => Ok(__FieldTag::__language_supported),
2900                            _ => Ok(__FieldTag::Unknown(value.to_string())),
2901                        }
2902                    }
2903                }
2904                deserializer.deserialize_identifier(Visitor)
2905            }
2906        }
2907        struct Visitor;
2908        impl<'de> serde::de::Visitor<'de> for Visitor {
2909            type Value = AnalyzeEntitiesResponse;
2910            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
2911                formatter.write_str("struct AnalyzeEntitiesResponse")
2912            }
2913            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
2914            where
2915                A: serde::de::MapAccess<'de>,
2916            {
2917                #[allow(unused_imports)]
2918                use serde::de::Error;
2919                use std::option::Option::Some;
2920                let mut fields = std::collections::HashSet::new();
2921                let mut result = Self::Value::new();
2922                while let Some(tag) = map.next_key::<__FieldTag>()? {
2923                    #[allow(clippy::match_single_binding)]
2924                    match tag {
2925                        __FieldTag::__entities => {
2926                            if !fields.insert(__FieldTag::__entities) {
2927                                return std::result::Result::Err(A::Error::duplicate_field(
2928                                    "multiple values for entities",
2929                                ));
2930                            }
2931                            result.entities = map.next_value::<std::option::Option<std::vec::Vec<crate::model::Entity>>>()?.unwrap_or_default();
2932                        }
2933                        __FieldTag::__language_code => {
2934                            if !fields.insert(__FieldTag::__language_code) {
2935                                return std::result::Result::Err(A::Error::duplicate_field(
2936                                    "multiple values for language_code",
2937                                ));
2938                            }
2939                            result.language_code = map
2940                                .next_value::<std::option::Option<std::string::String>>()?
2941                                .unwrap_or_default();
2942                        }
2943                        __FieldTag::__language_supported => {
2944                            if !fields.insert(__FieldTag::__language_supported) {
2945                                return std::result::Result::Err(A::Error::duplicate_field(
2946                                    "multiple values for language_supported",
2947                                ));
2948                            }
2949                            result.language_supported = map
2950                                .next_value::<std::option::Option<bool>>()?
2951                                .unwrap_or_default();
2952                        }
2953                        __FieldTag::Unknown(key) => {
2954                            let value = map.next_value::<serde_json::Value>()?;
2955                            result._unknown_fields.insert(key, value);
2956                        }
2957                    }
2958                }
2959                std::result::Result::Ok(result)
2960            }
2961        }
2962        deserializer.deserialize_any(Visitor)
2963    }
2964}
2965
2966#[doc(hidden)]
2967impl serde::ser::Serialize for AnalyzeEntitiesResponse {
2968    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
2969    where
2970        S: serde::ser::Serializer,
2971    {
2972        use serde::ser::SerializeMap;
2973        #[allow(unused_imports)]
2974        use std::option::Option::Some;
2975        let mut state = serializer.serialize_map(std::option::Option::None)?;
2976        if !self.entities.is_empty() {
2977            state.serialize_entry("entities", &self.entities)?;
2978        }
2979        if !self.language_code.is_empty() {
2980            state.serialize_entry("languageCode", &self.language_code)?;
2981        }
2982        if !wkt::internal::is_default(&self.language_supported) {
2983            state.serialize_entry("languageSupported", &self.language_supported)?;
2984        }
2985        if !self._unknown_fields.is_empty() {
2986            for (key, value) in self._unknown_fields.iter() {
2987                state.serialize_entry(key, &value)?;
2988            }
2989        }
2990        state.end()
2991    }
2992}
2993
2994impl std::fmt::Debug for AnalyzeEntitiesResponse {
2995    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2996        let mut debug_struct = f.debug_struct("AnalyzeEntitiesResponse");
2997        debug_struct.field("entities", &self.entities);
2998        debug_struct.field("language_code", &self.language_code);
2999        debug_struct.field("language_supported", &self.language_supported);
3000        if !self._unknown_fields.is_empty() {
3001            debug_struct.field("_unknown_fields", &self._unknown_fields);
3002        }
3003        debug_struct.finish()
3004    }
3005}
3006
3007/// The document classification request message.
3008#[derive(Clone, Default, PartialEq)]
3009#[non_exhaustive]
3010pub struct ClassifyTextRequest {
3011    /// Required. Input document.
3012    pub document: std::option::Option<crate::model::Document>,
3013
3014    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
3015}
3016
3017impl ClassifyTextRequest {
3018    pub fn new() -> Self {
3019        std::default::Default::default()
3020    }
3021
3022    /// Sets the value of [document][crate::model::ClassifyTextRequest::document].
3023    pub fn set_document<T>(mut self, v: T) -> Self
3024    where
3025        T: std::convert::Into<crate::model::Document>,
3026    {
3027        self.document = std::option::Option::Some(v.into());
3028        self
3029    }
3030
3031    /// Sets or clears the value of [document][crate::model::ClassifyTextRequest::document].
3032    pub fn set_or_clear_document<T>(mut self, v: std::option::Option<T>) -> Self
3033    where
3034        T: std::convert::Into<crate::model::Document>,
3035    {
3036        self.document = v.map(|x| x.into());
3037        self
3038    }
3039}
3040
3041impl wkt::message::Message for ClassifyTextRequest {
3042    fn typename() -> &'static str {
3043        "type.googleapis.com/google.cloud.language.v2.ClassifyTextRequest"
3044    }
3045}
3046
3047#[doc(hidden)]
3048impl<'de> serde::de::Deserialize<'de> for ClassifyTextRequest {
3049    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
3050    where
3051        D: serde::Deserializer<'de>,
3052    {
3053        #[allow(non_camel_case_types)]
3054        #[doc(hidden)]
3055        #[derive(PartialEq, Eq, Hash)]
3056        enum __FieldTag {
3057            __document,
3058            Unknown(std::string::String),
3059        }
3060        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
3061            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
3062            where
3063                D: serde::Deserializer<'de>,
3064            {
3065                struct Visitor;
3066                impl<'de> serde::de::Visitor<'de> for Visitor {
3067                    type Value = __FieldTag;
3068                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
3069                        formatter.write_str("a field name for ClassifyTextRequest")
3070                    }
3071                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
3072                    where
3073                        E: serde::de::Error,
3074                    {
3075                        use std::result::Result::Ok;
3076                        use std::string::ToString;
3077                        match value {
3078                            "document" => Ok(__FieldTag::__document),
3079                            _ => Ok(__FieldTag::Unknown(value.to_string())),
3080                        }
3081                    }
3082                }
3083                deserializer.deserialize_identifier(Visitor)
3084            }
3085        }
3086        struct Visitor;
3087        impl<'de> serde::de::Visitor<'de> for Visitor {
3088            type Value = ClassifyTextRequest;
3089            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
3090                formatter.write_str("struct ClassifyTextRequest")
3091            }
3092            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
3093            where
3094                A: serde::de::MapAccess<'de>,
3095            {
3096                #[allow(unused_imports)]
3097                use serde::de::Error;
3098                use std::option::Option::Some;
3099                let mut fields = std::collections::HashSet::new();
3100                let mut result = Self::Value::new();
3101                while let Some(tag) = map.next_key::<__FieldTag>()? {
3102                    #[allow(clippy::match_single_binding)]
3103                    match tag {
3104                        __FieldTag::__document => {
3105                            if !fields.insert(__FieldTag::__document) {
3106                                return std::result::Result::Err(A::Error::duplicate_field(
3107                                    "multiple values for document",
3108                                ));
3109                            }
3110                            result.document =
3111                                map.next_value::<std::option::Option<crate::model::Document>>()?;
3112                        }
3113                        __FieldTag::Unknown(key) => {
3114                            let value = map.next_value::<serde_json::Value>()?;
3115                            result._unknown_fields.insert(key, value);
3116                        }
3117                    }
3118                }
3119                std::result::Result::Ok(result)
3120            }
3121        }
3122        deserializer.deserialize_any(Visitor)
3123    }
3124}
3125
3126#[doc(hidden)]
3127impl serde::ser::Serialize for ClassifyTextRequest {
3128    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
3129    where
3130        S: serde::ser::Serializer,
3131    {
3132        use serde::ser::SerializeMap;
3133        #[allow(unused_imports)]
3134        use std::option::Option::Some;
3135        let mut state = serializer.serialize_map(std::option::Option::None)?;
3136        if self.document.is_some() {
3137            state.serialize_entry("document", &self.document)?;
3138        }
3139        if !self._unknown_fields.is_empty() {
3140            for (key, value) in self._unknown_fields.iter() {
3141                state.serialize_entry(key, &value)?;
3142            }
3143        }
3144        state.end()
3145    }
3146}
3147
3148impl std::fmt::Debug for ClassifyTextRequest {
3149    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3150        let mut debug_struct = f.debug_struct("ClassifyTextRequest");
3151        debug_struct.field("document", &self.document);
3152        if !self._unknown_fields.is_empty() {
3153            debug_struct.field("_unknown_fields", &self._unknown_fields);
3154        }
3155        debug_struct.finish()
3156    }
3157}
3158
3159/// The document classification response message.
3160#[derive(Clone, Default, PartialEq)]
3161#[non_exhaustive]
3162pub struct ClassifyTextResponse {
3163    /// Categories representing the input document.
3164    pub categories: std::vec::Vec<crate::model::ClassificationCategory>,
3165
3166    /// The language of the text, which will be the same as the language specified
3167    /// in the request or, if not specified, the automatically-detected language.
3168    /// See [Document.language][] field for more details.
3169    pub language_code: std::string::String,
3170
3171    /// Whether the language is officially supported. The API may still return a
3172    /// response when the language is not supported, but it is on a best effort
3173    /// basis.
3174    pub language_supported: bool,
3175
3176    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
3177}
3178
3179impl ClassifyTextResponse {
3180    pub fn new() -> Self {
3181        std::default::Default::default()
3182    }
3183
3184    /// Sets the value of [categories][crate::model::ClassifyTextResponse::categories].
3185    pub fn set_categories<T, V>(mut self, v: T) -> Self
3186    where
3187        T: std::iter::IntoIterator<Item = V>,
3188        V: std::convert::Into<crate::model::ClassificationCategory>,
3189    {
3190        use std::iter::Iterator;
3191        self.categories = v.into_iter().map(|i| i.into()).collect();
3192        self
3193    }
3194
3195    /// Sets the value of [language_code][crate::model::ClassifyTextResponse::language_code].
3196    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
3197        self.language_code = v.into();
3198        self
3199    }
3200
3201    /// Sets the value of [language_supported][crate::model::ClassifyTextResponse::language_supported].
3202    pub fn set_language_supported<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
3203        self.language_supported = v.into();
3204        self
3205    }
3206}
3207
3208impl wkt::message::Message for ClassifyTextResponse {
3209    fn typename() -> &'static str {
3210        "type.googleapis.com/google.cloud.language.v2.ClassifyTextResponse"
3211    }
3212}
3213
3214#[doc(hidden)]
3215impl<'de> serde::de::Deserialize<'de> for ClassifyTextResponse {
3216    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
3217    where
3218        D: serde::Deserializer<'de>,
3219    {
3220        #[allow(non_camel_case_types)]
3221        #[doc(hidden)]
3222        #[derive(PartialEq, Eq, Hash)]
3223        enum __FieldTag {
3224            __categories,
3225            __language_code,
3226            __language_supported,
3227            Unknown(std::string::String),
3228        }
3229        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
3230            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
3231            where
3232                D: serde::Deserializer<'de>,
3233            {
3234                struct Visitor;
3235                impl<'de> serde::de::Visitor<'de> for Visitor {
3236                    type Value = __FieldTag;
3237                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
3238                        formatter.write_str("a field name for ClassifyTextResponse")
3239                    }
3240                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
3241                    where
3242                        E: serde::de::Error,
3243                    {
3244                        use std::result::Result::Ok;
3245                        use std::string::ToString;
3246                        match value {
3247                            "categories" => Ok(__FieldTag::__categories),
3248                            "languageCode" => Ok(__FieldTag::__language_code),
3249                            "language_code" => Ok(__FieldTag::__language_code),
3250                            "languageSupported" => Ok(__FieldTag::__language_supported),
3251                            "language_supported" => Ok(__FieldTag::__language_supported),
3252                            _ => Ok(__FieldTag::Unknown(value.to_string())),
3253                        }
3254                    }
3255                }
3256                deserializer.deserialize_identifier(Visitor)
3257            }
3258        }
3259        struct Visitor;
3260        impl<'de> serde::de::Visitor<'de> for Visitor {
3261            type Value = ClassifyTextResponse;
3262            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
3263                formatter.write_str("struct ClassifyTextResponse")
3264            }
3265            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
3266            where
3267                A: serde::de::MapAccess<'de>,
3268            {
3269                #[allow(unused_imports)]
3270                use serde::de::Error;
3271                use std::option::Option::Some;
3272                let mut fields = std::collections::HashSet::new();
3273                let mut result = Self::Value::new();
3274                while let Some(tag) = map.next_key::<__FieldTag>()? {
3275                    #[allow(clippy::match_single_binding)]
3276                    match tag {
3277                        __FieldTag::__categories => {
3278                            if !fields.insert(__FieldTag::__categories) {
3279                                return std::result::Result::Err(A::Error::duplicate_field(
3280                                    "multiple values for categories",
3281                                ));
3282                            }
3283                            result.categories = map
3284                                .next_value::<std::option::Option<
3285                                    std::vec::Vec<crate::model::ClassificationCategory>,
3286                                >>()?
3287                                .unwrap_or_default();
3288                        }
3289                        __FieldTag::__language_code => {
3290                            if !fields.insert(__FieldTag::__language_code) {
3291                                return std::result::Result::Err(A::Error::duplicate_field(
3292                                    "multiple values for language_code",
3293                                ));
3294                            }
3295                            result.language_code = map
3296                                .next_value::<std::option::Option<std::string::String>>()?
3297                                .unwrap_or_default();
3298                        }
3299                        __FieldTag::__language_supported => {
3300                            if !fields.insert(__FieldTag::__language_supported) {
3301                                return std::result::Result::Err(A::Error::duplicate_field(
3302                                    "multiple values for language_supported",
3303                                ));
3304                            }
3305                            result.language_supported = map
3306                                .next_value::<std::option::Option<bool>>()?
3307                                .unwrap_or_default();
3308                        }
3309                        __FieldTag::Unknown(key) => {
3310                            let value = map.next_value::<serde_json::Value>()?;
3311                            result._unknown_fields.insert(key, value);
3312                        }
3313                    }
3314                }
3315                std::result::Result::Ok(result)
3316            }
3317        }
3318        deserializer.deserialize_any(Visitor)
3319    }
3320}
3321
3322#[doc(hidden)]
3323impl serde::ser::Serialize for ClassifyTextResponse {
3324    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
3325    where
3326        S: serde::ser::Serializer,
3327    {
3328        use serde::ser::SerializeMap;
3329        #[allow(unused_imports)]
3330        use std::option::Option::Some;
3331        let mut state = serializer.serialize_map(std::option::Option::None)?;
3332        if !self.categories.is_empty() {
3333            state.serialize_entry("categories", &self.categories)?;
3334        }
3335        if !self.language_code.is_empty() {
3336            state.serialize_entry("languageCode", &self.language_code)?;
3337        }
3338        if !wkt::internal::is_default(&self.language_supported) {
3339            state.serialize_entry("languageSupported", &self.language_supported)?;
3340        }
3341        if !self._unknown_fields.is_empty() {
3342            for (key, value) in self._unknown_fields.iter() {
3343                state.serialize_entry(key, &value)?;
3344            }
3345        }
3346        state.end()
3347    }
3348}
3349
3350impl std::fmt::Debug for ClassifyTextResponse {
3351    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3352        let mut debug_struct = f.debug_struct("ClassifyTextResponse");
3353        debug_struct.field("categories", &self.categories);
3354        debug_struct.field("language_code", &self.language_code);
3355        debug_struct.field("language_supported", &self.language_supported);
3356        if !self._unknown_fields.is_empty() {
3357            debug_struct.field("_unknown_fields", &self._unknown_fields);
3358        }
3359        debug_struct.finish()
3360    }
3361}
3362
3363/// The document moderation request message.
3364#[derive(Clone, Default, PartialEq)]
3365#[non_exhaustive]
3366pub struct ModerateTextRequest {
3367    /// Required. Input document.
3368    pub document: std::option::Option<crate::model::Document>,
3369
3370    /// Optional. The model version to use for ModerateText.
3371    pub model_version: crate::model::moderate_text_request::ModelVersion,
3372
3373    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
3374}
3375
3376impl ModerateTextRequest {
3377    pub fn new() -> Self {
3378        std::default::Default::default()
3379    }
3380
3381    /// Sets the value of [document][crate::model::ModerateTextRequest::document].
3382    pub fn set_document<T>(mut self, v: T) -> Self
3383    where
3384        T: std::convert::Into<crate::model::Document>,
3385    {
3386        self.document = std::option::Option::Some(v.into());
3387        self
3388    }
3389
3390    /// Sets or clears the value of [document][crate::model::ModerateTextRequest::document].
3391    pub fn set_or_clear_document<T>(mut self, v: std::option::Option<T>) -> Self
3392    where
3393        T: std::convert::Into<crate::model::Document>,
3394    {
3395        self.document = v.map(|x| x.into());
3396        self
3397    }
3398
3399    /// Sets the value of [model_version][crate::model::ModerateTextRequest::model_version].
3400    pub fn set_model_version<
3401        T: std::convert::Into<crate::model::moderate_text_request::ModelVersion>,
3402    >(
3403        mut self,
3404        v: T,
3405    ) -> Self {
3406        self.model_version = v.into();
3407        self
3408    }
3409}
3410
3411impl wkt::message::Message for ModerateTextRequest {
3412    fn typename() -> &'static str {
3413        "type.googleapis.com/google.cloud.language.v2.ModerateTextRequest"
3414    }
3415}
3416
3417#[doc(hidden)]
3418impl<'de> serde::de::Deserialize<'de> for ModerateTextRequest {
3419    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
3420    where
3421        D: serde::Deserializer<'de>,
3422    {
3423        #[allow(non_camel_case_types)]
3424        #[doc(hidden)]
3425        #[derive(PartialEq, Eq, Hash)]
3426        enum __FieldTag {
3427            __document,
3428            __model_version,
3429            Unknown(std::string::String),
3430        }
3431        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
3432            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
3433            where
3434                D: serde::Deserializer<'de>,
3435            {
3436                struct Visitor;
3437                impl<'de> serde::de::Visitor<'de> for Visitor {
3438                    type Value = __FieldTag;
3439                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
3440                        formatter.write_str("a field name for ModerateTextRequest")
3441                    }
3442                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
3443                    where
3444                        E: serde::de::Error,
3445                    {
3446                        use std::result::Result::Ok;
3447                        use std::string::ToString;
3448                        match value {
3449                            "document" => Ok(__FieldTag::__document),
3450                            "modelVersion" => Ok(__FieldTag::__model_version),
3451                            "model_version" => Ok(__FieldTag::__model_version),
3452                            _ => Ok(__FieldTag::Unknown(value.to_string())),
3453                        }
3454                    }
3455                }
3456                deserializer.deserialize_identifier(Visitor)
3457            }
3458        }
3459        struct Visitor;
3460        impl<'de> serde::de::Visitor<'de> for Visitor {
3461            type Value = ModerateTextRequest;
3462            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
3463                formatter.write_str("struct ModerateTextRequest")
3464            }
3465            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
3466            where
3467                A: serde::de::MapAccess<'de>,
3468            {
3469                #[allow(unused_imports)]
3470                use serde::de::Error;
3471                use std::option::Option::Some;
3472                let mut fields = std::collections::HashSet::new();
3473                let mut result = Self::Value::new();
3474                while let Some(tag) = map.next_key::<__FieldTag>()? {
3475                    #[allow(clippy::match_single_binding)]
3476                    match tag {
3477                        __FieldTag::__document => {
3478                            if !fields.insert(__FieldTag::__document) {
3479                                return std::result::Result::Err(A::Error::duplicate_field(
3480                                    "multiple values for document",
3481                                ));
3482                            }
3483                            result.document =
3484                                map.next_value::<std::option::Option<crate::model::Document>>()?;
3485                        }
3486                        __FieldTag::__model_version => {
3487                            if !fields.insert(__FieldTag::__model_version) {
3488                                return std::result::Result::Err(A::Error::duplicate_field(
3489                                    "multiple values for model_version",
3490                                ));
3491                            }
3492                            result.model_version = map
3493                                .next_value::<std::option::Option<
3494                                    crate::model::moderate_text_request::ModelVersion,
3495                                >>()?
3496                                .unwrap_or_default();
3497                        }
3498                        __FieldTag::Unknown(key) => {
3499                            let value = map.next_value::<serde_json::Value>()?;
3500                            result._unknown_fields.insert(key, value);
3501                        }
3502                    }
3503                }
3504                std::result::Result::Ok(result)
3505            }
3506        }
3507        deserializer.deserialize_any(Visitor)
3508    }
3509}
3510
3511#[doc(hidden)]
3512impl serde::ser::Serialize for ModerateTextRequest {
3513    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
3514    where
3515        S: serde::ser::Serializer,
3516    {
3517        use serde::ser::SerializeMap;
3518        #[allow(unused_imports)]
3519        use std::option::Option::Some;
3520        let mut state = serializer.serialize_map(std::option::Option::None)?;
3521        if self.document.is_some() {
3522            state.serialize_entry("document", &self.document)?;
3523        }
3524        if !wkt::internal::is_default(&self.model_version) {
3525            state.serialize_entry("modelVersion", &self.model_version)?;
3526        }
3527        if !self._unknown_fields.is_empty() {
3528            for (key, value) in self._unknown_fields.iter() {
3529                state.serialize_entry(key, &value)?;
3530            }
3531        }
3532        state.end()
3533    }
3534}
3535
3536impl std::fmt::Debug for ModerateTextRequest {
3537    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3538        let mut debug_struct = f.debug_struct("ModerateTextRequest");
3539        debug_struct.field("document", &self.document);
3540        debug_struct.field("model_version", &self.model_version);
3541        if !self._unknown_fields.is_empty() {
3542            debug_struct.field("_unknown_fields", &self._unknown_fields);
3543        }
3544        debug_struct.finish()
3545    }
3546}
3547
3548/// Defines additional types related to [ModerateTextRequest].
3549pub mod moderate_text_request {
3550    #[allow(unused_imports)]
3551    use super::*;
3552
3553    /// The model version to use for ModerateText.
3554    ///
3555    /// # Working with unknown values
3556    ///
3557    /// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
3558    /// additional enum variants at any time. Adding new variants is not considered
3559    /// a breaking change. Applications should write their code in anticipation of:
3560    ///
3561    /// - New values appearing in future releases of the client library, **and**
3562    /// - New values received dynamically, without application changes.
3563    ///
3564    /// Please consult the [Working with enums] section in the user guide for some
3565    /// guidelines.
3566    ///
3567    /// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
3568    #[derive(Clone, Debug, PartialEq)]
3569    #[non_exhaustive]
3570    pub enum ModelVersion {
3571        /// The default model version.
3572        Unspecified,
3573        /// Use the v1 model, this model is used by default when not provided.
3574        /// The v1 model only returns probability (confidence) score for each
3575        /// category.
3576        ModelVersion1,
3577        /// Use the v2 model.
3578        /// The v2 model only returns probability (confidence) score for each
3579        /// category, and returns severity score for a subset of the categories.
3580        ModelVersion2,
3581        /// If set, the enum was initialized with an unknown value.
3582        ///
3583        /// Applications can examine the value using [ModelVersion::value] or
3584        /// [ModelVersion::name].
3585        UnknownValue(model_version::UnknownValue),
3586    }
3587
3588    #[doc(hidden)]
3589    pub mod model_version {
3590        #[allow(unused_imports)]
3591        use super::*;
3592        #[derive(Clone, Debug, PartialEq)]
3593        pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
3594    }
3595
3596    impl ModelVersion {
3597        /// Gets the enum value.
3598        ///
3599        /// Returns `None` if the enum contains an unknown value deserialized from
3600        /// the string representation of enums.
3601        pub fn value(&self) -> std::option::Option<i32> {
3602            match self {
3603                Self::Unspecified => std::option::Option::Some(0),
3604                Self::ModelVersion1 => std::option::Option::Some(1),
3605                Self::ModelVersion2 => std::option::Option::Some(2),
3606                Self::UnknownValue(u) => u.0.value(),
3607            }
3608        }
3609
3610        /// Gets the enum value as a string.
3611        ///
3612        /// Returns `None` if the enum contains an unknown value deserialized from
3613        /// the integer representation of enums.
3614        pub fn name(&self) -> std::option::Option<&str> {
3615            match self {
3616                Self::Unspecified => std::option::Option::Some("MODEL_VERSION_UNSPECIFIED"),
3617                Self::ModelVersion1 => std::option::Option::Some("MODEL_VERSION_1"),
3618                Self::ModelVersion2 => std::option::Option::Some("MODEL_VERSION_2"),
3619                Self::UnknownValue(u) => u.0.name(),
3620            }
3621        }
3622    }
3623
3624    impl std::default::Default for ModelVersion {
3625        fn default() -> Self {
3626            use std::convert::From;
3627            Self::from(0)
3628        }
3629    }
3630
3631    impl std::fmt::Display for ModelVersion {
3632        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
3633            wkt::internal::display_enum(f, self.name(), self.value())
3634        }
3635    }
3636
3637    impl std::convert::From<i32> for ModelVersion {
3638        fn from(value: i32) -> Self {
3639            match value {
3640                0 => Self::Unspecified,
3641                1 => Self::ModelVersion1,
3642                2 => Self::ModelVersion2,
3643                _ => Self::UnknownValue(model_version::UnknownValue(
3644                    wkt::internal::UnknownEnumValue::Integer(value),
3645                )),
3646            }
3647        }
3648    }
3649
3650    impl std::convert::From<&str> for ModelVersion {
3651        fn from(value: &str) -> Self {
3652            use std::string::ToString;
3653            match value {
3654                "MODEL_VERSION_UNSPECIFIED" => Self::Unspecified,
3655                "MODEL_VERSION_1" => Self::ModelVersion1,
3656                "MODEL_VERSION_2" => Self::ModelVersion2,
3657                _ => Self::UnknownValue(model_version::UnknownValue(
3658                    wkt::internal::UnknownEnumValue::String(value.to_string()),
3659                )),
3660            }
3661        }
3662    }
3663
3664    impl serde::ser::Serialize for ModelVersion {
3665        fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
3666        where
3667            S: serde::Serializer,
3668        {
3669            match self {
3670                Self::Unspecified => serializer.serialize_i32(0),
3671                Self::ModelVersion1 => serializer.serialize_i32(1),
3672                Self::ModelVersion2 => serializer.serialize_i32(2),
3673                Self::UnknownValue(u) => u.0.serialize(serializer),
3674            }
3675        }
3676    }
3677
3678    impl<'de> serde::de::Deserialize<'de> for ModelVersion {
3679        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
3680        where
3681            D: serde::Deserializer<'de>,
3682        {
3683            deserializer.deserialize_any(wkt::internal::EnumVisitor::<ModelVersion>::new(
3684                ".google.cloud.language.v2.ModerateTextRequest.ModelVersion",
3685            ))
3686        }
3687    }
3688}
3689
3690/// The document moderation response message.
3691#[derive(Clone, Default, PartialEq)]
3692#[non_exhaustive]
3693pub struct ModerateTextResponse {
3694    /// Harmful and sensitive categories representing the input document.
3695    pub moderation_categories: std::vec::Vec<crate::model::ClassificationCategory>,
3696
3697    /// The language of the text, which will be the same as the language specified
3698    /// in the request or, if not specified, the automatically-detected language.
3699    /// See [Document.language][] field for more details.
3700    pub language_code: std::string::String,
3701
3702    /// Whether the language is officially supported. The API may still return a
3703    /// response when the language is not supported, but it is on a best effort
3704    /// basis.
3705    pub language_supported: bool,
3706
3707    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
3708}
3709
3710impl ModerateTextResponse {
3711    pub fn new() -> Self {
3712        std::default::Default::default()
3713    }
3714
3715    /// Sets the value of [moderation_categories][crate::model::ModerateTextResponse::moderation_categories].
3716    pub fn set_moderation_categories<T, V>(mut self, v: T) -> Self
3717    where
3718        T: std::iter::IntoIterator<Item = V>,
3719        V: std::convert::Into<crate::model::ClassificationCategory>,
3720    {
3721        use std::iter::Iterator;
3722        self.moderation_categories = v.into_iter().map(|i| i.into()).collect();
3723        self
3724    }
3725
3726    /// Sets the value of [language_code][crate::model::ModerateTextResponse::language_code].
3727    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
3728        self.language_code = v.into();
3729        self
3730    }
3731
3732    /// Sets the value of [language_supported][crate::model::ModerateTextResponse::language_supported].
3733    pub fn set_language_supported<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
3734        self.language_supported = v.into();
3735        self
3736    }
3737}
3738
3739impl wkt::message::Message for ModerateTextResponse {
3740    fn typename() -> &'static str {
3741        "type.googleapis.com/google.cloud.language.v2.ModerateTextResponse"
3742    }
3743}
3744
3745#[doc(hidden)]
3746impl<'de> serde::de::Deserialize<'de> for ModerateTextResponse {
3747    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
3748    where
3749        D: serde::Deserializer<'de>,
3750    {
3751        #[allow(non_camel_case_types)]
3752        #[doc(hidden)]
3753        #[derive(PartialEq, Eq, Hash)]
3754        enum __FieldTag {
3755            __moderation_categories,
3756            __language_code,
3757            __language_supported,
3758            Unknown(std::string::String),
3759        }
3760        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
3761            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
3762            where
3763                D: serde::Deserializer<'de>,
3764            {
3765                struct Visitor;
3766                impl<'de> serde::de::Visitor<'de> for Visitor {
3767                    type Value = __FieldTag;
3768                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
3769                        formatter.write_str("a field name for ModerateTextResponse")
3770                    }
3771                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
3772                    where
3773                        E: serde::de::Error,
3774                    {
3775                        use std::result::Result::Ok;
3776                        use std::string::ToString;
3777                        match value {
3778                            "moderationCategories" => Ok(__FieldTag::__moderation_categories),
3779                            "moderation_categories" => Ok(__FieldTag::__moderation_categories),
3780                            "languageCode" => Ok(__FieldTag::__language_code),
3781                            "language_code" => Ok(__FieldTag::__language_code),
3782                            "languageSupported" => Ok(__FieldTag::__language_supported),
3783                            "language_supported" => Ok(__FieldTag::__language_supported),
3784                            _ => Ok(__FieldTag::Unknown(value.to_string())),
3785                        }
3786                    }
3787                }
3788                deserializer.deserialize_identifier(Visitor)
3789            }
3790        }
3791        struct Visitor;
3792        impl<'de> serde::de::Visitor<'de> for Visitor {
3793            type Value = ModerateTextResponse;
3794            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
3795                formatter.write_str("struct ModerateTextResponse")
3796            }
3797            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
3798            where
3799                A: serde::de::MapAccess<'de>,
3800            {
3801                #[allow(unused_imports)]
3802                use serde::de::Error;
3803                use std::option::Option::Some;
3804                let mut fields = std::collections::HashSet::new();
3805                let mut result = Self::Value::new();
3806                while let Some(tag) = map.next_key::<__FieldTag>()? {
3807                    #[allow(clippy::match_single_binding)]
3808                    match tag {
3809                        __FieldTag::__moderation_categories => {
3810                            if !fields.insert(__FieldTag::__moderation_categories) {
3811                                return std::result::Result::Err(A::Error::duplicate_field(
3812                                    "multiple values for moderation_categories",
3813                                ));
3814                            }
3815                            result.moderation_categories = map
3816                                .next_value::<std::option::Option<
3817                                    std::vec::Vec<crate::model::ClassificationCategory>,
3818                                >>()?
3819                                .unwrap_or_default();
3820                        }
3821                        __FieldTag::__language_code => {
3822                            if !fields.insert(__FieldTag::__language_code) {
3823                                return std::result::Result::Err(A::Error::duplicate_field(
3824                                    "multiple values for language_code",
3825                                ));
3826                            }
3827                            result.language_code = map
3828                                .next_value::<std::option::Option<std::string::String>>()?
3829                                .unwrap_or_default();
3830                        }
3831                        __FieldTag::__language_supported => {
3832                            if !fields.insert(__FieldTag::__language_supported) {
3833                                return std::result::Result::Err(A::Error::duplicate_field(
3834                                    "multiple values for language_supported",
3835                                ));
3836                            }
3837                            result.language_supported = map
3838                                .next_value::<std::option::Option<bool>>()?
3839                                .unwrap_or_default();
3840                        }
3841                        __FieldTag::Unknown(key) => {
3842                            let value = map.next_value::<serde_json::Value>()?;
3843                            result._unknown_fields.insert(key, value);
3844                        }
3845                    }
3846                }
3847                std::result::Result::Ok(result)
3848            }
3849        }
3850        deserializer.deserialize_any(Visitor)
3851    }
3852}
3853
3854#[doc(hidden)]
3855impl serde::ser::Serialize for ModerateTextResponse {
3856    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
3857    where
3858        S: serde::ser::Serializer,
3859    {
3860        use serde::ser::SerializeMap;
3861        #[allow(unused_imports)]
3862        use std::option::Option::Some;
3863        let mut state = serializer.serialize_map(std::option::Option::None)?;
3864        if !self.moderation_categories.is_empty() {
3865            state.serialize_entry("moderationCategories", &self.moderation_categories)?;
3866        }
3867        if !self.language_code.is_empty() {
3868            state.serialize_entry("languageCode", &self.language_code)?;
3869        }
3870        if !wkt::internal::is_default(&self.language_supported) {
3871            state.serialize_entry("languageSupported", &self.language_supported)?;
3872        }
3873        if !self._unknown_fields.is_empty() {
3874            for (key, value) in self._unknown_fields.iter() {
3875                state.serialize_entry(key, &value)?;
3876            }
3877        }
3878        state.end()
3879    }
3880}
3881
3882impl std::fmt::Debug for ModerateTextResponse {
3883    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3884        let mut debug_struct = f.debug_struct("ModerateTextResponse");
3885        debug_struct.field("moderation_categories", &self.moderation_categories);
3886        debug_struct.field("language_code", &self.language_code);
3887        debug_struct.field("language_supported", &self.language_supported);
3888        if !self._unknown_fields.is_empty() {
3889            debug_struct.field("_unknown_fields", &self._unknown_fields);
3890        }
3891        debug_struct.finish()
3892    }
3893}
3894
3895/// The request message for the text annotation API, which can perform multiple
3896/// analysis types in one call.
3897#[derive(Clone, Default, PartialEq)]
3898#[non_exhaustive]
3899pub struct AnnotateTextRequest {
3900    /// Required. Input document.
3901    pub document: std::option::Option<crate::model::Document>,
3902
3903    /// Required. The enabled features.
3904    pub features: std::option::Option<crate::model::annotate_text_request::Features>,
3905
3906    /// The encoding type used by the API to calculate offsets.
3907    pub encoding_type: crate::model::EncodingType,
3908
3909    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
3910}
3911
3912impl AnnotateTextRequest {
3913    pub fn new() -> Self {
3914        std::default::Default::default()
3915    }
3916
3917    /// Sets the value of [document][crate::model::AnnotateTextRequest::document].
3918    pub fn set_document<T>(mut self, v: T) -> Self
3919    where
3920        T: std::convert::Into<crate::model::Document>,
3921    {
3922        self.document = std::option::Option::Some(v.into());
3923        self
3924    }
3925
3926    /// Sets or clears the value of [document][crate::model::AnnotateTextRequest::document].
3927    pub fn set_or_clear_document<T>(mut self, v: std::option::Option<T>) -> Self
3928    where
3929        T: std::convert::Into<crate::model::Document>,
3930    {
3931        self.document = v.map(|x| x.into());
3932        self
3933    }
3934
3935    /// Sets the value of [features][crate::model::AnnotateTextRequest::features].
3936    pub fn set_features<T>(mut self, v: T) -> Self
3937    where
3938        T: std::convert::Into<crate::model::annotate_text_request::Features>,
3939    {
3940        self.features = std::option::Option::Some(v.into());
3941        self
3942    }
3943
3944    /// Sets or clears the value of [features][crate::model::AnnotateTextRequest::features].
3945    pub fn set_or_clear_features<T>(mut self, v: std::option::Option<T>) -> Self
3946    where
3947        T: std::convert::Into<crate::model::annotate_text_request::Features>,
3948    {
3949        self.features = v.map(|x| x.into());
3950        self
3951    }
3952
3953    /// Sets the value of [encoding_type][crate::model::AnnotateTextRequest::encoding_type].
3954    pub fn set_encoding_type<T: std::convert::Into<crate::model::EncodingType>>(
3955        mut self,
3956        v: T,
3957    ) -> Self {
3958        self.encoding_type = v.into();
3959        self
3960    }
3961}
3962
3963impl wkt::message::Message for AnnotateTextRequest {
3964    fn typename() -> &'static str {
3965        "type.googleapis.com/google.cloud.language.v2.AnnotateTextRequest"
3966    }
3967}
3968
3969#[doc(hidden)]
3970impl<'de> serde::de::Deserialize<'de> for AnnotateTextRequest {
3971    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
3972    where
3973        D: serde::Deserializer<'de>,
3974    {
3975        #[allow(non_camel_case_types)]
3976        #[doc(hidden)]
3977        #[derive(PartialEq, Eq, Hash)]
3978        enum __FieldTag {
3979            __document,
3980            __features,
3981            __encoding_type,
3982            Unknown(std::string::String),
3983        }
3984        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
3985            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
3986            where
3987                D: serde::Deserializer<'de>,
3988            {
3989                struct Visitor;
3990                impl<'de> serde::de::Visitor<'de> for Visitor {
3991                    type Value = __FieldTag;
3992                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
3993                        formatter.write_str("a field name for AnnotateTextRequest")
3994                    }
3995                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
3996                    where
3997                        E: serde::de::Error,
3998                    {
3999                        use std::result::Result::Ok;
4000                        use std::string::ToString;
4001                        match value {
4002                            "document" => Ok(__FieldTag::__document),
4003                            "features" => Ok(__FieldTag::__features),
4004                            "encodingType" => Ok(__FieldTag::__encoding_type),
4005                            "encoding_type" => Ok(__FieldTag::__encoding_type),
4006                            _ => Ok(__FieldTag::Unknown(value.to_string())),
4007                        }
4008                    }
4009                }
4010                deserializer.deserialize_identifier(Visitor)
4011            }
4012        }
4013        struct Visitor;
4014        impl<'de> serde::de::Visitor<'de> for Visitor {
4015            type Value = AnnotateTextRequest;
4016            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
4017                formatter.write_str("struct AnnotateTextRequest")
4018            }
4019            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
4020            where
4021                A: serde::de::MapAccess<'de>,
4022            {
4023                #[allow(unused_imports)]
4024                use serde::de::Error;
4025                use std::option::Option::Some;
4026                let mut fields = std::collections::HashSet::new();
4027                let mut result = Self::Value::new();
4028                while let Some(tag) = map.next_key::<__FieldTag>()? {
4029                    #[allow(clippy::match_single_binding)]
4030                    match tag {
4031                        __FieldTag::__document => {
4032                            if !fields.insert(__FieldTag::__document) {
4033                                return std::result::Result::Err(A::Error::duplicate_field(
4034                                    "multiple values for document",
4035                                ));
4036                            }
4037                            result.document =
4038                                map.next_value::<std::option::Option<crate::model::Document>>()?;
4039                        }
4040                        __FieldTag::__features => {
4041                            if !fields.insert(__FieldTag::__features) {
4042                                return std::result::Result::Err(A::Error::duplicate_field(
4043                                    "multiple values for features",
4044                                ));
4045                            }
4046                            result.features = map.next_value::<std::option::Option<
4047                                crate::model::annotate_text_request::Features,
4048                            >>()?;
4049                        }
4050                        __FieldTag::__encoding_type => {
4051                            if !fields.insert(__FieldTag::__encoding_type) {
4052                                return std::result::Result::Err(A::Error::duplicate_field(
4053                                    "multiple values for encoding_type",
4054                                ));
4055                            }
4056                            result.encoding_type = map
4057                                .next_value::<std::option::Option<crate::model::EncodingType>>()?
4058                                .unwrap_or_default();
4059                        }
4060                        __FieldTag::Unknown(key) => {
4061                            let value = map.next_value::<serde_json::Value>()?;
4062                            result._unknown_fields.insert(key, value);
4063                        }
4064                    }
4065                }
4066                std::result::Result::Ok(result)
4067            }
4068        }
4069        deserializer.deserialize_any(Visitor)
4070    }
4071}
4072
4073#[doc(hidden)]
4074impl serde::ser::Serialize for AnnotateTextRequest {
4075    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
4076    where
4077        S: serde::ser::Serializer,
4078    {
4079        use serde::ser::SerializeMap;
4080        #[allow(unused_imports)]
4081        use std::option::Option::Some;
4082        let mut state = serializer.serialize_map(std::option::Option::None)?;
4083        if self.document.is_some() {
4084            state.serialize_entry("document", &self.document)?;
4085        }
4086        if self.features.is_some() {
4087            state.serialize_entry("features", &self.features)?;
4088        }
4089        if !wkt::internal::is_default(&self.encoding_type) {
4090            state.serialize_entry("encodingType", &self.encoding_type)?;
4091        }
4092        if !self._unknown_fields.is_empty() {
4093            for (key, value) in self._unknown_fields.iter() {
4094                state.serialize_entry(key, &value)?;
4095            }
4096        }
4097        state.end()
4098    }
4099}
4100
4101impl std::fmt::Debug for AnnotateTextRequest {
4102    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4103        let mut debug_struct = f.debug_struct("AnnotateTextRequest");
4104        debug_struct.field("document", &self.document);
4105        debug_struct.field("features", &self.features);
4106        debug_struct.field("encoding_type", &self.encoding_type);
4107        if !self._unknown_fields.is_empty() {
4108            debug_struct.field("_unknown_fields", &self._unknown_fields);
4109        }
4110        debug_struct.finish()
4111    }
4112}
4113
4114/// Defines additional types related to [AnnotateTextRequest].
4115pub mod annotate_text_request {
4116    #[allow(unused_imports)]
4117    use super::*;
4118
4119    /// All available features.
4120    /// Setting each one to true will enable that specific analysis for the input.
4121    #[derive(Clone, Default, PartialEq)]
4122    #[non_exhaustive]
4123    pub struct Features {
4124        /// Optional. Extract entities.
4125        pub extract_entities: bool,
4126
4127        /// Optional. Extract document-level sentiment.
4128        pub extract_document_sentiment: bool,
4129
4130        /// Optional. Classify the full document into categories.
4131        pub classify_text: bool,
4132
4133        /// Optional. Moderate the document for harmful and sensitive categories.
4134        pub moderate_text: bool,
4135
4136        _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
4137    }
4138
4139    impl Features {
4140        pub fn new() -> Self {
4141            std::default::Default::default()
4142        }
4143
4144        /// Sets the value of [extract_entities][crate::model::annotate_text_request::Features::extract_entities].
4145        pub fn set_extract_entities<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
4146            self.extract_entities = v.into();
4147            self
4148        }
4149
4150        /// Sets the value of [extract_document_sentiment][crate::model::annotate_text_request::Features::extract_document_sentiment].
4151        pub fn set_extract_document_sentiment<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
4152            self.extract_document_sentiment = v.into();
4153            self
4154        }
4155
4156        /// Sets the value of [classify_text][crate::model::annotate_text_request::Features::classify_text].
4157        pub fn set_classify_text<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
4158            self.classify_text = v.into();
4159            self
4160        }
4161
4162        /// Sets the value of [moderate_text][crate::model::annotate_text_request::Features::moderate_text].
4163        pub fn set_moderate_text<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
4164            self.moderate_text = v.into();
4165            self
4166        }
4167    }
4168
4169    impl wkt::message::Message for Features {
4170        fn typename() -> &'static str {
4171            "type.googleapis.com/google.cloud.language.v2.AnnotateTextRequest.Features"
4172        }
4173    }
4174
4175    #[doc(hidden)]
4176    impl<'de> serde::de::Deserialize<'de> for Features {
4177        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
4178        where
4179            D: serde::Deserializer<'de>,
4180        {
4181            #[allow(non_camel_case_types)]
4182            #[doc(hidden)]
4183            #[derive(PartialEq, Eq, Hash)]
4184            enum __FieldTag {
4185                __extract_entities,
4186                __extract_document_sentiment,
4187                __classify_text,
4188                __moderate_text,
4189                Unknown(std::string::String),
4190            }
4191            impl<'de> serde::de::Deserialize<'de> for __FieldTag {
4192                fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
4193                where
4194                    D: serde::Deserializer<'de>,
4195                {
4196                    struct Visitor;
4197                    impl<'de> serde::de::Visitor<'de> for Visitor {
4198                        type Value = __FieldTag;
4199                        fn expecting(
4200                            &self,
4201                            formatter: &mut std::fmt::Formatter,
4202                        ) -> std::fmt::Result {
4203                            formatter.write_str("a field name for Features")
4204                        }
4205                        fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
4206                        where
4207                            E: serde::de::Error,
4208                        {
4209                            use std::result::Result::Ok;
4210                            use std::string::ToString;
4211                            match value {
4212                                "extractEntities" => Ok(__FieldTag::__extract_entities),
4213                                "extract_entities" => Ok(__FieldTag::__extract_entities),
4214                                "extractDocumentSentiment" => {
4215                                    Ok(__FieldTag::__extract_document_sentiment)
4216                                }
4217                                "extract_document_sentiment" => {
4218                                    Ok(__FieldTag::__extract_document_sentiment)
4219                                }
4220                                "classifyText" => Ok(__FieldTag::__classify_text),
4221                                "classify_text" => Ok(__FieldTag::__classify_text),
4222                                "moderateText" => Ok(__FieldTag::__moderate_text),
4223                                "moderate_text" => Ok(__FieldTag::__moderate_text),
4224                                _ => Ok(__FieldTag::Unknown(value.to_string())),
4225                            }
4226                        }
4227                    }
4228                    deserializer.deserialize_identifier(Visitor)
4229                }
4230            }
4231            struct Visitor;
4232            impl<'de> serde::de::Visitor<'de> for Visitor {
4233                type Value = Features;
4234                fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
4235                    formatter.write_str("struct Features")
4236                }
4237                fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
4238                where
4239                    A: serde::de::MapAccess<'de>,
4240                {
4241                    #[allow(unused_imports)]
4242                    use serde::de::Error;
4243                    use std::option::Option::Some;
4244                    let mut fields = std::collections::HashSet::new();
4245                    let mut result = Self::Value::new();
4246                    while let Some(tag) = map.next_key::<__FieldTag>()? {
4247                        #[allow(clippy::match_single_binding)]
4248                        match tag {
4249                            __FieldTag::__extract_entities => {
4250                                if !fields.insert(__FieldTag::__extract_entities) {
4251                                    return std::result::Result::Err(A::Error::duplicate_field(
4252                                        "multiple values for extract_entities",
4253                                    ));
4254                                }
4255                                result.extract_entities = map
4256                                    .next_value::<std::option::Option<bool>>()?
4257                                    .unwrap_or_default();
4258                            }
4259                            __FieldTag::__extract_document_sentiment => {
4260                                if !fields.insert(__FieldTag::__extract_document_sentiment) {
4261                                    return std::result::Result::Err(A::Error::duplicate_field(
4262                                        "multiple values for extract_document_sentiment",
4263                                    ));
4264                                }
4265                                result.extract_document_sentiment = map
4266                                    .next_value::<std::option::Option<bool>>()?
4267                                    .unwrap_or_default();
4268                            }
4269                            __FieldTag::__classify_text => {
4270                                if !fields.insert(__FieldTag::__classify_text) {
4271                                    return std::result::Result::Err(A::Error::duplicate_field(
4272                                        "multiple values for classify_text",
4273                                    ));
4274                                }
4275                                result.classify_text = map
4276                                    .next_value::<std::option::Option<bool>>()?
4277                                    .unwrap_or_default();
4278                            }
4279                            __FieldTag::__moderate_text => {
4280                                if !fields.insert(__FieldTag::__moderate_text) {
4281                                    return std::result::Result::Err(A::Error::duplicate_field(
4282                                        "multiple values for moderate_text",
4283                                    ));
4284                                }
4285                                result.moderate_text = map
4286                                    .next_value::<std::option::Option<bool>>()?
4287                                    .unwrap_or_default();
4288                            }
4289                            __FieldTag::Unknown(key) => {
4290                                let value = map.next_value::<serde_json::Value>()?;
4291                                result._unknown_fields.insert(key, value);
4292                            }
4293                        }
4294                    }
4295                    std::result::Result::Ok(result)
4296                }
4297            }
4298            deserializer.deserialize_any(Visitor)
4299        }
4300    }
4301
4302    #[doc(hidden)]
4303    impl serde::ser::Serialize for Features {
4304        fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
4305        where
4306            S: serde::ser::Serializer,
4307        {
4308            use serde::ser::SerializeMap;
4309            #[allow(unused_imports)]
4310            use std::option::Option::Some;
4311            let mut state = serializer.serialize_map(std::option::Option::None)?;
4312            if !wkt::internal::is_default(&self.extract_entities) {
4313                state.serialize_entry("extractEntities", &self.extract_entities)?;
4314            }
4315            if !wkt::internal::is_default(&self.extract_document_sentiment) {
4316                state.serialize_entry(
4317                    "extractDocumentSentiment",
4318                    &self.extract_document_sentiment,
4319                )?;
4320            }
4321            if !wkt::internal::is_default(&self.classify_text) {
4322                state.serialize_entry("classifyText", &self.classify_text)?;
4323            }
4324            if !wkt::internal::is_default(&self.moderate_text) {
4325                state.serialize_entry("moderateText", &self.moderate_text)?;
4326            }
4327            if !self._unknown_fields.is_empty() {
4328                for (key, value) in self._unknown_fields.iter() {
4329                    state.serialize_entry(key, &value)?;
4330                }
4331            }
4332            state.end()
4333        }
4334    }
4335
4336    impl std::fmt::Debug for Features {
4337        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4338            let mut debug_struct = f.debug_struct("Features");
4339            debug_struct.field("extract_entities", &self.extract_entities);
4340            debug_struct.field(
4341                "extract_document_sentiment",
4342                &self.extract_document_sentiment,
4343            );
4344            debug_struct.field("classify_text", &self.classify_text);
4345            debug_struct.field("moderate_text", &self.moderate_text);
4346            if !self._unknown_fields.is_empty() {
4347                debug_struct.field("_unknown_fields", &self._unknown_fields);
4348            }
4349            debug_struct.finish()
4350        }
4351    }
4352}
4353
4354/// The text annotations response message.
4355#[derive(Clone, Default, PartialEq)]
4356#[non_exhaustive]
4357pub struct AnnotateTextResponse {
4358    /// Sentences in the input document. Populated if the user enables
4359    /// [AnnotateTextRequest.Features.extract_document_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment].
4360    ///
4361    /// [google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment]: crate::model::annotate_text_request::Features::extract_document_sentiment
4362    pub sentences: std::vec::Vec<crate::model::Sentence>,
4363
4364    /// Entities, along with their semantic information, in the input document.
4365    /// Populated if the user enables
4366    /// [AnnotateTextRequest.Features.extract_entities][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entities]
4367    /// or
4368    /// [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entity_sentiment].
4369    ///
4370    /// [google.cloud.language.v2.AnnotateTextRequest.Features.extract_entities]: crate::model::annotate_text_request::Features::extract_entities
4371    pub entities: std::vec::Vec<crate::model::Entity>,
4372
4373    /// The overall sentiment for the document. Populated if the user enables
4374    /// [AnnotateTextRequest.Features.extract_document_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment].
4375    ///
4376    /// [google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment]: crate::model::annotate_text_request::Features::extract_document_sentiment
4377    pub document_sentiment: std::option::Option<crate::model::Sentiment>,
4378
4379    /// The language of the text, which will be the same as the language specified
4380    /// in the request or, if not specified, the automatically-detected language.
4381    /// See [Document.language][] field for more details.
4382    pub language_code: std::string::String,
4383
4384    /// Categories identified in the input document.
4385    pub categories: std::vec::Vec<crate::model::ClassificationCategory>,
4386
4387    /// Harmful and sensitive categories identified in the input document.
4388    pub moderation_categories: std::vec::Vec<crate::model::ClassificationCategory>,
4389
4390    /// Whether the language is officially supported by all requested features.
4391    /// The API may still return a response when the language is not supported, but
4392    /// it is on a best effort basis.
4393    pub language_supported: bool,
4394
4395    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
4396}
4397
4398impl AnnotateTextResponse {
4399    pub fn new() -> Self {
4400        std::default::Default::default()
4401    }
4402
4403    /// Sets the value of [sentences][crate::model::AnnotateTextResponse::sentences].
4404    pub fn set_sentences<T, V>(mut self, v: T) -> Self
4405    where
4406        T: std::iter::IntoIterator<Item = V>,
4407        V: std::convert::Into<crate::model::Sentence>,
4408    {
4409        use std::iter::Iterator;
4410        self.sentences = v.into_iter().map(|i| i.into()).collect();
4411        self
4412    }
4413
4414    /// Sets the value of [entities][crate::model::AnnotateTextResponse::entities].
4415    pub fn set_entities<T, V>(mut self, v: T) -> Self
4416    where
4417        T: std::iter::IntoIterator<Item = V>,
4418        V: std::convert::Into<crate::model::Entity>,
4419    {
4420        use std::iter::Iterator;
4421        self.entities = v.into_iter().map(|i| i.into()).collect();
4422        self
4423    }
4424
4425    /// Sets the value of [document_sentiment][crate::model::AnnotateTextResponse::document_sentiment].
4426    pub fn set_document_sentiment<T>(mut self, v: T) -> Self
4427    where
4428        T: std::convert::Into<crate::model::Sentiment>,
4429    {
4430        self.document_sentiment = std::option::Option::Some(v.into());
4431        self
4432    }
4433
4434    /// Sets or clears the value of [document_sentiment][crate::model::AnnotateTextResponse::document_sentiment].
4435    pub fn set_or_clear_document_sentiment<T>(mut self, v: std::option::Option<T>) -> Self
4436    where
4437        T: std::convert::Into<crate::model::Sentiment>,
4438    {
4439        self.document_sentiment = v.map(|x| x.into());
4440        self
4441    }
4442
4443    /// Sets the value of [language_code][crate::model::AnnotateTextResponse::language_code].
4444    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
4445        self.language_code = v.into();
4446        self
4447    }
4448
4449    /// Sets the value of [categories][crate::model::AnnotateTextResponse::categories].
4450    pub fn set_categories<T, V>(mut self, v: T) -> Self
4451    where
4452        T: std::iter::IntoIterator<Item = V>,
4453        V: std::convert::Into<crate::model::ClassificationCategory>,
4454    {
4455        use std::iter::Iterator;
4456        self.categories = v.into_iter().map(|i| i.into()).collect();
4457        self
4458    }
4459
4460    /// Sets the value of [moderation_categories][crate::model::AnnotateTextResponse::moderation_categories].
4461    pub fn set_moderation_categories<T, V>(mut self, v: T) -> Self
4462    where
4463        T: std::iter::IntoIterator<Item = V>,
4464        V: std::convert::Into<crate::model::ClassificationCategory>,
4465    {
4466        use std::iter::Iterator;
4467        self.moderation_categories = v.into_iter().map(|i| i.into()).collect();
4468        self
4469    }
4470
4471    /// Sets the value of [language_supported][crate::model::AnnotateTextResponse::language_supported].
4472    pub fn set_language_supported<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
4473        self.language_supported = v.into();
4474        self
4475    }
4476}
4477
4478impl wkt::message::Message for AnnotateTextResponse {
4479    fn typename() -> &'static str {
4480        "type.googleapis.com/google.cloud.language.v2.AnnotateTextResponse"
4481    }
4482}
4483
4484#[doc(hidden)]
4485impl<'de> serde::de::Deserialize<'de> for AnnotateTextResponse {
4486    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
4487    where
4488        D: serde::Deserializer<'de>,
4489    {
4490        #[allow(non_camel_case_types)]
4491        #[doc(hidden)]
4492        #[derive(PartialEq, Eq, Hash)]
4493        enum __FieldTag {
4494            __sentences,
4495            __entities,
4496            __document_sentiment,
4497            __language_code,
4498            __categories,
4499            __moderation_categories,
4500            __language_supported,
4501            Unknown(std::string::String),
4502        }
4503        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
4504            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
4505            where
4506                D: serde::Deserializer<'de>,
4507            {
4508                struct Visitor;
4509                impl<'de> serde::de::Visitor<'de> for Visitor {
4510                    type Value = __FieldTag;
4511                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
4512                        formatter.write_str("a field name for AnnotateTextResponse")
4513                    }
4514                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
4515                    where
4516                        E: serde::de::Error,
4517                    {
4518                        use std::result::Result::Ok;
4519                        use std::string::ToString;
4520                        match value {
4521                            "sentences" => Ok(__FieldTag::__sentences),
4522                            "entities" => Ok(__FieldTag::__entities),
4523                            "documentSentiment" => Ok(__FieldTag::__document_sentiment),
4524                            "document_sentiment" => Ok(__FieldTag::__document_sentiment),
4525                            "languageCode" => Ok(__FieldTag::__language_code),
4526                            "language_code" => Ok(__FieldTag::__language_code),
4527                            "categories" => Ok(__FieldTag::__categories),
4528                            "moderationCategories" => Ok(__FieldTag::__moderation_categories),
4529                            "moderation_categories" => Ok(__FieldTag::__moderation_categories),
4530                            "languageSupported" => Ok(__FieldTag::__language_supported),
4531                            "language_supported" => Ok(__FieldTag::__language_supported),
4532                            _ => Ok(__FieldTag::Unknown(value.to_string())),
4533                        }
4534                    }
4535                }
4536                deserializer.deserialize_identifier(Visitor)
4537            }
4538        }
4539        struct Visitor;
4540        impl<'de> serde::de::Visitor<'de> for Visitor {
4541            type Value = AnnotateTextResponse;
4542            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
4543                formatter.write_str("struct AnnotateTextResponse")
4544            }
4545            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
4546            where
4547                A: serde::de::MapAccess<'de>,
4548            {
4549                #[allow(unused_imports)]
4550                use serde::de::Error;
4551                use std::option::Option::Some;
4552                let mut fields = std::collections::HashSet::new();
4553                let mut result = Self::Value::new();
4554                while let Some(tag) = map.next_key::<__FieldTag>()? {
4555                    #[allow(clippy::match_single_binding)]
4556                    match tag {
4557                        __FieldTag::__sentences => {
4558                            if !fields.insert(__FieldTag::__sentences) {
4559                                return std::result::Result::Err(A::Error::duplicate_field(
4560                                    "multiple values for sentences",
4561                                ));
4562                            }
4563                            result.sentences = map.next_value::<std::option::Option<std::vec::Vec<crate::model::Sentence>>>()?.unwrap_or_default();
4564                        }
4565                        __FieldTag::__entities => {
4566                            if !fields.insert(__FieldTag::__entities) {
4567                                return std::result::Result::Err(A::Error::duplicate_field(
4568                                    "multiple values for entities",
4569                                ));
4570                            }
4571                            result.entities = map.next_value::<std::option::Option<std::vec::Vec<crate::model::Entity>>>()?.unwrap_or_default();
4572                        }
4573                        __FieldTag::__document_sentiment => {
4574                            if !fields.insert(__FieldTag::__document_sentiment) {
4575                                return std::result::Result::Err(A::Error::duplicate_field(
4576                                    "multiple values for document_sentiment",
4577                                ));
4578                            }
4579                            result.document_sentiment =
4580                                map.next_value::<std::option::Option<crate::model::Sentiment>>()?;
4581                        }
4582                        __FieldTag::__language_code => {
4583                            if !fields.insert(__FieldTag::__language_code) {
4584                                return std::result::Result::Err(A::Error::duplicate_field(
4585                                    "multiple values for language_code",
4586                                ));
4587                            }
4588                            result.language_code = map
4589                                .next_value::<std::option::Option<std::string::String>>()?
4590                                .unwrap_or_default();
4591                        }
4592                        __FieldTag::__categories => {
4593                            if !fields.insert(__FieldTag::__categories) {
4594                                return std::result::Result::Err(A::Error::duplicate_field(
4595                                    "multiple values for categories",
4596                                ));
4597                            }
4598                            result.categories = map
4599                                .next_value::<std::option::Option<
4600                                    std::vec::Vec<crate::model::ClassificationCategory>,
4601                                >>()?
4602                                .unwrap_or_default();
4603                        }
4604                        __FieldTag::__moderation_categories => {
4605                            if !fields.insert(__FieldTag::__moderation_categories) {
4606                                return std::result::Result::Err(A::Error::duplicate_field(
4607                                    "multiple values for moderation_categories",
4608                                ));
4609                            }
4610                            result.moderation_categories = map
4611                                .next_value::<std::option::Option<
4612                                    std::vec::Vec<crate::model::ClassificationCategory>,
4613                                >>()?
4614                                .unwrap_or_default();
4615                        }
4616                        __FieldTag::__language_supported => {
4617                            if !fields.insert(__FieldTag::__language_supported) {
4618                                return std::result::Result::Err(A::Error::duplicate_field(
4619                                    "multiple values for language_supported",
4620                                ));
4621                            }
4622                            result.language_supported = map
4623                                .next_value::<std::option::Option<bool>>()?
4624                                .unwrap_or_default();
4625                        }
4626                        __FieldTag::Unknown(key) => {
4627                            let value = map.next_value::<serde_json::Value>()?;
4628                            result._unknown_fields.insert(key, value);
4629                        }
4630                    }
4631                }
4632                std::result::Result::Ok(result)
4633            }
4634        }
4635        deserializer.deserialize_any(Visitor)
4636    }
4637}
4638
4639#[doc(hidden)]
4640impl serde::ser::Serialize for AnnotateTextResponse {
4641    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
4642    where
4643        S: serde::ser::Serializer,
4644    {
4645        use serde::ser::SerializeMap;
4646        #[allow(unused_imports)]
4647        use std::option::Option::Some;
4648        let mut state = serializer.serialize_map(std::option::Option::None)?;
4649        if !self.sentences.is_empty() {
4650            state.serialize_entry("sentences", &self.sentences)?;
4651        }
4652        if !self.entities.is_empty() {
4653            state.serialize_entry("entities", &self.entities)?;
4654        }
4655        if self.document_sentiment.is_some() {
4656            state.serialize_entry("documentSentiment", &self.document_sentiment)?;
4657        }
4658        if !self.language_code.is_empty() {
4659            state.serialize_entry("languageCode", &self.language_code)?;
4660        }
4661        if !self.categories.is_empty() {
4662            state.serialize_entry("categories", &self.categories)?;
4663        }
4664        if !self.moderation_categories.is_empty() {
4665            state.serialize_entry("moderationCategories", &self.moderation_categories)?;
4666        }
4667        if !wkt::internal::is_default(&self.language_supported) {
4668            state.serialize_entry("languageSupported", &self.language_supported)?;
4669        }
4670        if !self._unknown_fields.is_empty() {
4671            for (key, value) in self._unknown_fields.iter() {
4672                state.serialize_entry(key, &value)?;
4673            }
4674        }
4675        state.end()
4676    }
4677}
4678
4679impl std::fmt::Debug for AnnotateTextResponse {
4680    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4681        let mut debug_struct = f.debug_struct("AnnotateTextResponse");
4682        debug_struct.field("sentences", &self.sentences);
4683        debug_struct.field("entities", &self.entities);
4684        debug_struct.field("document_sentiment", &self.document_sentiment);
4685        debug_struct.field("language_code", &self.language_code);
4686        debug_struct.field("categories", &self.categories);
4687        debug_struct.field("moderation_categories", &self.moderation_categories);
4688        debug_struct.field("language_supported", &self.language_supported);
4689        if !self._unknown_fields.is_empty() {
4690            debug_struct.field("_unknown_fields", &self._unknown_fields);
4691        }
4692        debug_struct.finish()
4693    }
4694}
4695
4696/// Represents the text encoding that the caller uses to process the output.
4697/// Providing an `EncodingType` is recommended because the API provides the
4698/// beginning offsets for various outputs, such as tokens and mentions, and
4699/// languages that natively use different text encodings may access offsets
4700/// differently.
4701///
4702/// # Working with unknown values
4703///
4704/// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
4705/// additional enum variants at any time. Adding new variants is not considered
4706/// a breaking change. Applications should write their code in anticipation of:
4707///
4708/// - New values appearing in future releases of the client library, **and**
4709/// - New values received dynamically, without application changes.
4710///
4711/// Please consult the [Working with enums] section in the user guide for some
4712/// guidelines.
4713///
4714/// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
4715#[derive(Clone, Debug, PartialEq)]
4716#[non_exhaustive]
4717pub enum EncodingType {
4718    /// If `EncodingType` is not specified, encoding-dependent information (such as
4719    /// `begin_offset`) will be set at `-1`.
4720    None,
4721    /// Encoding-dependent information (such as `begin_offset`) is calculated based
4722    /// on the UTF-8 encoding of the input. C++ and Go are examples of languages
4723    /// that use this encoding natively.
4724    Utf8,
4725    /// Encoding-dependent information (such as `begin_offset`) is calculated based
4726    /// on the UTF-16 encoding of the input. Java and JavaScript are examples of
4727    /// languages that use this encoding natively.
4728    Utf16,
4729    /// Encoding-dependent information (such as `begin_offset`) is calculated based
4730    /// on the UTF-32 encoding of the input. Python is an example of a language
4731    /// that uses this encoding natively.
4732    Utf32,
4733    /// If set, the enum was initialized with an unknown value.
4734    ///
4735    /// Applications can examine the value using [EncodingType::value] or
4736    /// [EncodingType::name].
4737    UnknownValue(encoding_type::UnknownValue),
4738}
4739
4740#[doc(hidden)]
4741pub mod encoding_type {
4742    #[allow(unused_imports)]
4743    use super::*;
4744    #[derive(Clone, Debug, PartialEq)]
4745    pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
4746}
4747
4748impl EncodingType {
4749    /// Gets the enum value.
4750    ///
4751    /// Returns `None` if the enum contains an unknown value deserialized from
4752    /// the string representation of enums.
4753    pub fn value(&self) -> std::option::Option<i32> {
4754        match self {
4755            Self::None => std::option::Option::Some(0),
4756            Self::Utf8 => std::option::Option::Some(1),
4757            Self::Utf16 => std::option::Option::Some(2),
4758            Self::Utf32 => std::option::Option::Some(3),
4759            Self::UnknownValue(u) => u.0.value(),
4760        }
4761    }
4762
4763    /// Gets the enum value as a string.
4764    ///
4765    /// Returns `None` if the enum contains an unknown value deserialized from
4766    /// the integer representation of enums.
4767    pub fn name(&self) -> std::option::Option<&str> {
4768        match self {
4769            Self::None => std::option::Option::Some("NONE"),
4770            Self::Utf8 => std::option::Option::Some("UTF8"),
4771            Self::Utf16 => std::option::Option::Some("UTF16"),
4772            Self::Utf32 => std::option::Option::Some("UTF32"),
4773            Self::UnknownValue(u) => u.0.name(),
4774        }
4775    }
4776}
4777
4778impl std::default::Default for EncodingType {
4779    fn default() -> Self {
4780        use std::convert::From;
4781        Self::from(0)
4782    }
4783}
4784
4785impl std::fmt::Display for EncodingType {
4786    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
4787        wkt::internal::display_enum(f, self.name(), self.value())
4788    }
4789}
4790
4791impl std::convert::From<i32> for EncodingType {
4792    fn from(value: i32) -> Self {
4793        match value {
4794            0 => Self::None,
4795            1 => Self::Utf8,
4796            2 => Self::Utf16,
4797            3 => Self::Utf32,
4798            _ => Self::UnknownValue(encoding_type::UnknownValue(
4799                wkt::internal::UnknownEnumValue::Integer(value),
4800            )),
4801        }
4802    }
4803}
4804
4805impl std::convert::From<&str> for EncodingType {
4806    fn from(value: &str) -> Self {
4807        use std::string::ToString;
4808        match value {
4809            "NONE" => Self::None,
4810            "UTF8" => Self::Utf8,
4811            "UTF16" => Self::Utf16,
4812            "UTF32" => Self::Utf32,
4813            _ => Self::UnknownValue(encoding_type::UnknownValue(
4814                wkt::internal::UnknownEnumValue::String(value.to_string()),
4815            )),
4816        }
4817    }
4818}
4819
4820impl serde::ser::Serialize for EncodingType {
4821    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
4822    where
4823        S: serde::Serializer,
4824    {
4825        match self {
4826            Self::None => serializer.serialize_i32(0),
4827            Self::Utf8 => serializer.serialize_i32(1),
4828            Self::Utf16 => serializer.serialize_i32(2),
4829            Self::Utf32 => serializer.serialize_i32(3),
4830            Self::UnknownValue(u) => u.0.serialize(serializer),
4831        }
4832    }
4833}
4834
4835impl<'de> serde::de::Deserialize<'de> for EncodingType {
4836    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
4837    where
4838        D: serde::Deserializer<'de>,
4839    {
4840        deserializer.deserialize_any(wkt::internal::EnumVisitor::<EncodingType>::new(
4841            ".google.cloud.language.v2.EncodingType",
4842        ))
4843    }
4844}