Exemplo n.º 1
0
 internal KnowledgeBaseAnswer(IReadOnlyList <string> questions, string answer, double?confidence, int?qnaId, string source, IReadOnlyDictionary <string, string> metadata, KnowledgeBaseAnswerDialog dialog, AnswerSpan shortAnswer)
 {
     Questions   = questions;
     Answer      = answer;
     Confidence  = confidence;
     QnaId       = qnaId;
     Source      = source;
     Metadata    = metadata;
     Dialog      = dialog;
     ShortAnswer = shortAnswer;
 }
Exemplo n.º 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));
        }
Exemplo n.º 3
0
        internal static TextAnswer DeserializeTextAnswer(JsonElement element)
        {
            Optional <string>     answer          = default;
            Optional <double>     confidenceScore = default;
            Optional <string>     id         = default;
            Optional <AnswerSpan> answerSpan = default;
            Optional <int>        offset     = default;
            Optional <int>        length     = default;

            foreach (var property in element.EnumerateObject())
            {
                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"))
                {
                    id = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("answerSpan"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    answerSpan = AnswerSpan.DeserializeAnswerSpan(property.Value);
                    continue;
                }
                if (property.NameEquals("offset"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    offset = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("length"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    length = property.Value.GetInt32();
                    continue;
                }
            }
            return(new TextAnswer(answer.Value, Optional.ToNullable(confidenceScore), id.Value, answerSpan.Value, Optional.ToNullable(offset), Optional.ToNullable(length)));
        }
Exemplo n.º 4
0
 public static TextAnswer TextAnswer(string answer = null, double?confidence = null, string id = null, AnswerSpan shortAnswer = null, int?offset = null, int?length = null)
 {
     return(new TextAnswer(answer, confidence, id, shortAnswer, offset, length));
 }
Exemplo n.º 5
0
        public static KnowledgeBaseAnswer KnowledgeBaseAnswer(IEnumerable <string> questions = null, string answer = null, double?confidence = null, int?qnaId = null, string source = null, IReadOnlyDictionary <string, string> metadata = null, KnowledgeBaseAnswerDialog dialog = null, AnswerSpan shortAnswer = null)
        {
            questions ??= new List <string>();
            metadata ??= new Dictionary <string, string>();

            return(new KnowledgeBaseAnswer(questions?.ToList(), answer, confidence, qnaId, source, metadata, dialog, shortAnswer));
        }