Beispiel #1
0
        internal static DocumentSentiment DeserializeDocumentSentiment(JsonElement element)
        {
            string id = default;
            DocumentSentimentValue            sentiment      = default;
            DocumentStatistics                statistics     = default;
            SentimentConfidenceScorePerLabel  documentScores = default;
            IReadOnlyList <SentenceSentiment> sentences      = 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)
                    {
                        continue;
                    }
                    statistics = DocumentStatistics.DeserializeDocumentStatistics(property.Value);
                    continue;
                }
                if (property.NameEquals("documentScores"))
                {
                    documentScores = SentimentConfidenceScorePerLabel.DeserializeSentimentConfidenceScorePerLabel(property.Value);
                    continue;
                }
                if (property.NameEquals("sentences"))
                {
                    List <SentenceSentiment> array = new List <SentenceSentiment>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(SentenceSentiment.DeserializeSentenceSentiment(item));
                        }
                    }
                    sentences = array;
                    continue;
                }
            }
            return(new DocumentSentiment(id, sentiment, statistics, documentScores, sentences));
        }
Beispiel #2
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));
        }