コード例 #1
0
        internal DocumentSentiment(string id, DocumentSentimentValue sentiment, SentimentConfidenceScorePerLabel confidenceScores, IEnumerable <SentenceSentiment> sentences, IEnumerable <TextAnalyticsWarning> 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();
        }
コード例 #2
0
        internal static DocumentSentiment DeserializeDocumentSentiment(JsonElement element)
        {
            string id = default;
            DocumentSentimentValue               sentiment        = default;
            Optional <DocumentStatistics>        statistics       = default;
            SentimentConfidenceScorePerLabel     confidenceScores = default;
            IReadOnlyList <SentenceSentiment>    sentences        = default;
            IReadOnlyList <TextAnalyticsWarning> 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"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    statistics = DocumentStatistics.DeserializeDocumentStatistics(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> array = new List <TextAnalyticsWarning>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(TextAnalyticsWarning.DeserializeTextAnalyticsWarning(item));
                    }
                    warnings = array;
                    continue;
                }
            }
            return(new DocumentSentiment(id, sentiment, statistics.Value, confidenceScores, sentences, warnings));
        }
コード例 #3
0
 internal DocumentSentiment(string id, DocumentSentimentValue sentiment, DocumentStatistics statistics, SentimentConfidenceScorePerLabel confidenceScores, IReadOnlyList <SentenceSentiment> sentences, IReadOnlyList <TextAnalyticsWarning> warnings)
 {
     Id               = id;
     Sentiment        = sentiment;
     Statistics       = statistics;
     ConfidenceScores = confidenceScores;
     Sentences        = sentences;
     Warnings         = warnings;
 }
コード例 #4
0
 internal SentenceSentiment(string text, SentenceSentimentValue sentiment, SentimentConfidenceScorePerLabel confidenceScores, int offset, int length, IReadOnlyList <SentenceTarget> targets, IReadOnlyList <SentenceAssessment> assessments)
 {
     Text             = text;
     Sentiment        = sentiment;
     ConfidenceScores = confidenceScores;
     Offset           = offset;
     Length           = length;
     Targets          = targets;
     Assessments      = assessments;
 }
コード例 #5
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;
            Targets          = new ChangeTrackingList <SentenceTarget>();
            Assessments      = new ChangeTrackingList <SentenceAssessment>();
        }
コード例 #6
0
        internal static SentenceSentiment DeserializeSentenceSentiment(JsonElement element)
        {
            string text = default;
            SentenceSentimentValue           sentiment        = default;
            SentimentConfidenceScorePerLabel confidenceScores = default;
            int offset = default;
            int length = default;
            Optional <IReadOnlyList <SentenceTarget> >     targets     = default;
            Optional <IReadOnlyList <SentenceAssessment> > assessments = 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("targets"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <SentenceTarget> array = new List <SentenceTarget>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(SentenceTarget.DeserializeSentenceTarget(item));
                    }
                    targets = array;
                    continue;
                }
                if (property.NameEquals("assessments"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <SentenceAssessment> array = new List <SentenceAssessment>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(SentenceAssessment.DeserializeSentenceAssessment(item));
                    }
                    assessments = array;
                    continue;
                }
            }
            return(new SentenceSentiment(text, sentiment, confidenceScores, offset, length, Optional.ToList(targets), Optional.ToList(assessments)));
        }