Esempio n. 1
0
        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));
        }
        internal static ScoringProfile DeserializeScoringProfile(JsonElement element)
        {
            ScoringProfile result = new ScoringProfile();

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("name"))
                {
                    result.Name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("text"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    result.TextWeights = TextWeights.DeserializeTextWeights(property.Value);
                    continue;
                }
                if (property.NameEquals("functions"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    result.Functions = new List <ScoringFunction>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        result.Functions.Add(ScoringFunction.DeserializeScoringFunction(item));
                    }
                    continue;
                }
                if (property.NameEquals("functionAggregation"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    result.FunctionAggregation = property.Value.GetString().ToScoringFunctionAggregation();
                    continue;
                }
            }
            return(result);
        }