internal KnowledgeBaseAnswer(IReadOnlyList <string> questions, string answer, double?confidenceScore, int?id, string source, IReadOnlyDictionary <string, string> metadata, KnowledgeBaseAnswerDialog dialog, AnswerSpan answerSpan)
 {
     Questions       = questions;
     Answer          = answer;
     ConfidenceScore = confidenceScore;
     Id         = id;
     Source     = source;
     Metadata   = metadata;
     Dialog     = dialog;
     AnswerSpan = answerSpan;
 }
Beispiel #2
0
        internal static KnowledgeBaseAnswer DeserializeKnowledgeBaseAnswer(JsonElement element)
        {
            Optional <IReadOnlyList <string> > questions = default;
            Optional <string> answer          = default;
            Optional <double> confidenceScore = default;
            Optional <int>    id     = default;
            Optional <string> source = default;
            Optional <IReadOnlyDictionary <string, string> > metadata = default;
            Optional <KnowledgeBaseAnswerDialog>             dialog   = default;
            Optional <AnswerSpan> answerSpan = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("questions"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <string> array = new List <string>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(item.GetString());
                    }
                    questions = array;
                    continue;
                }
                if (property.NameEquals("answer"))
                {
                    answer = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("confidenceScore"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    confidenceScore = property.Value.GetDouble();
                    continue;
                }
                if (property.NameEquals("id"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    id = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("source"))
                {
                    source = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("metadata"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    Dictionary <string, string> dictionary = new Dictionary <string, string>();
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        dictionary.Add(property0.Name, property0.Value.GetString());
                    }
                    metadata = dictionary;
                    continue;
                }
                if (property.NameEquals("dialog"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    dialog = KnowledgeBaseAnswerDialog.DeserializeKnowledgeBaseAnswerDialog(property.Value);
                    continue;
                }
                if (property.NameEquals("answerSpan"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    answerSpan = AnswerSpan.DeserializeAnswerSpan(property.Value);
                    continue;
                }
            }
            return(new KnowledgeBaseAnswer(Optional.ToList(questions), answer.Value, Optional.ToNullable(confidenceScore), Optional.ToNullable(id), source.Value, Optional.ToDictionary(metadata), dialog.Value, answerSpan.Value));
        }
Beispiel #3
0
        public static KnowledgeBaseAnswer KnowledgeBaseAnswer(IEnumerable <string> questions = null, string answer = null, double?confidenceScore = null, int?id = null, string source = null, IReadOnlyDictionary <string, string> metadata = null, KnowledgeBaseAnswerDialog dialog = null, AnswerSpan answerSpan = null)
        {
            questions ??= new List <string>();
            metadata ??= new Dictionary <string, string>();

            return(new KnowledgeBaseAnswer(questions?.ToList(), answer, confidenceScore, id, source, metadata, dialog, answerSpan));
        }