Exemplo n.º 1
0
        internal SentenceOpinion(SentenceOpinionSentiment sentiment, AspectConfidenceScoreLabel confidenceScores, int offset, int length, string text, bool isNegated)
        {
            if (confidenceScores == null)
            {
                throw new ArgumentNullException(nameof(confidenceScores));
            }
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            Sentiment        = sentiment;
            ConfidenceScores = confidenceScores;
            Offset           = offset;
            Length           = length;
            Text             = text;
            IsNegated        = isNegated;
        }
        internal static SentenceOpinion DeserializeSentenceOpinion(JsonElement element)
        {
            SentenceOpinionSentiment   sentiment        = default;
            AspectConfidenceScoreLabel confidenceScores = default;
            int    offset    = default;
            int    length    = default;
            string text      = default;
            bool   isNegated = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("sentiment"))
                {
                    sentiment = new SentenceOpinionSentiment(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("confidenceScores"))
                {
                    confidenceScores = AspectConfidenceScoreLabel.DeserializeAspectConfidenceScoreLabel(property.Value);
                    continue;
                }
                if (property.NameEquals("offset"))
                {
                    offset = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("length"))
                {
                    length = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("text"))
                {
                    text = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("isNegated"))
                {
                    isNegated = property.Value.GetBoolean();
                    continue;
                }
            }
            return(new SentenceOpinion(sentiment, confidenceScores, offset, length, text, isNegated));
        }