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 SentenceSentiment(SentenceSentimentValue sentiment, SentimentConfidenceScorePerLabel sentenceScores, int offset, int length, IReadOnlyList <string> warnings)
 {
     Sentiment      = sentiment;
     SentenceScores = sentenceScores;
     Offset         = offset;
     Length         = length;
     Warnings       = warnings;
 }
Пример #3
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;
 }
Пример #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;
 }
Пример #5
0
        internal static SentenceSentiment DeserializeSentenceSentiment(JsonElement element)
        {
            SentenceSentimentValue           sentiment      = default;
            SentimentConfidenceScorePerLabel sentenceScores = default;
            int offset = default;
            int length = default;
            IReadOnlyList <string> warnings = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("sentiment"))
                {
                    sentiment = property.Value.GetString().ToSentenceSentimentValue();
                    continue;
                }
                if (property.NameEquals("sentenceScores"))
                {
                    sentenceScores = 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("warnings"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <string> array = new List <string>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(item.GetString());
                        }
                    }
                    warnings = array;
                    continue;
                }
            }
            return(new SentenceSentiment(sentiment, sentenceScores, offset, length, warnings));
        }
        internal SentenceSentiment(SentenceSentimentValue sentiment, SentimentConfidenceScorePerLabel sentenceScores, int offset, int length)
        {
            if (sentenceScores == null)
            {
                throw new ArgumentNullException(nameof(sentenceScores));
            }

            Sentiment      = sentiment;
            SentenceScores = sentenceScores;
            Offset         = offset;
            Length         = length;
        }
Пример #7
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>();
        }
Пример #8
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)));
        }
 public static string ToSerialString(this SentenceSentimentValue value) => value switch
 {