internal static SentenceSentiment DeserializeSentenceSentiment(JsonElement element)
        {
            string text = default;
            SentenceSentimentValue           sentiment        = default;
            SentimentConfidenceScorePerLabel confidenceScores = default;
            int offset = default;
            int length = default;
            Optional <IReadOnlyList <SentenceAspect> >  aspects  = default;
            Optional <IReadOnlyList <SentenceOpinion> > opinions = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("text"))
                {
                    text = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("sentiment"))
                {
                    sentiment = property.Value.GetString().ToSentenceSentimentValue();
                    continue;
                }
                if (property.NameEquals("confidenceScores"))
                {
                    confidenceScores = SentimentConfidenceScorePerLabel.DeserializeSentimentConfidenceScorePerLabel(property.Value);
                    continue;
                }
                if (property.NameEquals("offset"))
                {
                    offset = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("length"))
                {
                    length = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("aspects"))
                {
                    List <SentenceAspect> array = new List <SentenceAspect>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(SentenceAspect.DeserializeSentenceAspect(item));
                    }
                    aspects = array;
                    continue;
                }
                if (property.NameEquals("opinions"))
                {
                    List <SentenceOpinion> array = new List <SentenceOpinion>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(SentenceOpinion.DeserializeSentenceOpinion(item));
                    }
                    opinions = array;
                    continue;
                }
            }
            return(new SentenceSentiment(text, sentiment, confidenceScores, offset, length, Optional.ToList(aspects), Optional.ToList(opinions)));
        }
        internal DocumentSentiment(string id, DocumentSentimentValue sentiment, SentimentConfidenceScorePerLabel confidenceScores, IEnumerable <SentenceSentiment> sentences, IEnumerable <TextAnalyticsWarning_internal> warnings)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }
            if (confidenceScores == null)
            {
                throw new ArgumentNullException(nameof(confidenceScores));
            }
            if (sentences == null)
            {
                throw new ArgumentNullException(nameof(sentences));
            }
            if (warnings == null)
            {
                throw new ArgumentNullException(nameof(warnings));
            }

            Id               = id;
            Sentiment        = sentiment;
            ConfidenceScores = confidenceScores;
            Sentences        = sentences.ToList();
            Warnings         = warnings.ToList();
        }
 internal DocumentSentiment(string id, DocumentSentimentValue sentiment, TextDocumentStatistics?statistics, SentimentConfidenceScorePerLabel confidenceScores, IReadOnlyList <SentenceSentiment> sentences, IReadOnlyList <TextAnalyticsWarning_internal> warnings)
 {
     Id               = id;
     Sentiment        = sentiment;
     Statistics       = statistics;
     ConfidenceScores = confidenceScores;
     Sentences        = sentences;
     Warnings         = warnings;
 }
Exemplo n.º 4
0
 internal SentenceSentiment(string text, SentenceSentimentValue sentiment, SentimentConfidenceScorePerLabel confidenceScores, int offset, int length, IReadOnlyList <SentenceAspect> aspects, IReadOnlyList <SentenceOpinion> opinions)
 {
     Text             = text;
     Sentiment        = sentiment;
     ConfidenceScores = confidenceScores;
     Offset           = offset;
     Length           = length;
     Aspects          = aspects;
     Opinions         = opinions;
 }
        internal static DocumentSentiment DeserializeDocumentSentiment(JsonElement element)
        {
            string id = default;
            DocumentSentimentValue                        sentiment        = default;
            Optional <TextDocumentStatistics>             statistics       = default;
            SentimentConfidenceScorePerLabel              confidenceScores = default;
            IReadOnlyList <SentenceSentiment>             sentences        = default;
            IReadOnlyList <TextAnalyticsWarning_internal> warnings         = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("id"))
                {
                    id = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("sentiment"))
                {
                    sentiment = property.Value.GetString().ToDocumentSentimentValue();
                    continue;
                }
                if (property.NameEquals("statistics"))
                {
                    statistics = TextDocumentStatistics.DeserializeTextDocumentStatistics(property.Value);
                    continue;
                }
                if (property.NameEquals("confidenceScores"))
                {
                    confidenceScores = SentimentConfidenceScorePerLabel.DeserializeSentimentConfidenceScorePerLabel(property.Value);
                    continue;
                }
                if (property.NameEquals("sentences"))
                {
                    List <SentenceSentiment> array = new List <SentenceSentiment>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(SentenceSentiment.DeserializeSentenceSentiment(item));
                    }
                    sentences = array;
                    continue;
                }
                if (property.NameEquals("warnings"))
                {
                    List <TextAnalyticsWarning_internal> array = new List <TextAnalyticsWarning_internal>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(TextAnalyticsWarning_internal.DeserializeTextAnalyticsWarning_internal(item));
                    }
                    warnings = array;
                    continue;
                }
            }
            return(new DocumentSentiment(id, sentiment, Optional.ToNullable(statistics), confidenceScores, sentences, warnings));
        }
Exemplo n.º 6
0
        internal SentenceSentiment(string text, SentenceSentimentValue sentiment, SentimentConfidenceScorePerLabel confidenceScores, int offset, int length)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }
            if (confidenceScores == null)
            {
                throw new ArgumentNullException(nameof(confidenceScores));
            }

            Text             = text;
            Sentiment        = sentiment;
            ConfidenceScores = confidenceScores;
            Offset           = offset;
            Length           = length;
            Aspects          = new ChangeTrackingList <SentenceAspect>();
            Opinions         = new ChangeTrackingList <SentenceOpinion>();
        }