internal static ScoringProfile DeserializeScoringProfile(JsonElement element)
        {
            string                     name                = default;
            TextWeights                text                = default;
            IList <ScoringFunction>    functions           = default;
            ScoringFunctionAggregation?functionAggregation = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("text"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    text = TextWeights.DeserializeTextWeights(property.Value);
                    continue;
                }
                if (property.NameEquals("functions"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <ScoringFunction> array = new List <ScoringFunction>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(ScoringFunction.DeserializeScoringFunction(item));
                        }
                    }
                    functions = array;
                    continue;
                }
                if (property.NameEquals("functionAggregation"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    functionAggregation = property.Value.GetString().ToScoringFunctionAggregation();
                    continue;
                }
            }
            return(new ScoringProfile(name, text, functions, functionAggregation));
        }
Example #2
0
        internal static ScoringProfile DeserializeScoringProfile(JsonElement element)
        {
            string name = default;
            Optional <TextWeights> text = default;
            Optional <IList <ScoringFunction> >   functions           = default;
            Optional <ScoringFunctionAggregation> functionAggregation = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("text"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        text = null;
                        continue;
                    }
                    text = TextWeights.DeserializeTextWeights(property.Value);
                    continue;
                }
                if (property.NameEquals("functions"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <ScoringFunction> array = new List <ScoringFunction>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(ScoringFunction.DeserializeScoringFunction(item));
                    }
                    functions = array;
                    continue;
                }
                if (property.NameEquals("functionAggregation"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    functionAggregation = property.Value.GetString().ToScoringFunctionAggregation();
                    continue;
                }
            }
            return(new ScoringProfile(name, text.Value, Optional.ToList(functions), Optional.ToNullable(functionAggregation)));
        }