<commit_before>﻿using System.Collections.Generic;
using System.Linq;
using Engine.Core.Context;
using Engine.Core.Rules;
using LanguageExt;
using Engine.Core.Utils;
using Engine.DataTypes;
using FSharpUtils.Newtonsoft;

namespace Engine.Core
{
    public delegate Option<IRule> RulesRepository(ConfigurationPath path);


    public static class EngineCore
    {
        public delegate Option<ConfigurationValue> GetRuleValue(ConfigurationPath path);

        public static GetRuleValue GetRulesEvaluator(HashSet<Identity> identities, GetLoadedContextByIdentityType contextByIdentity, RulesRepository rules)
        {
            var identityTypes = identities.Select(x => x.Type).ToArray();
            var flattenContext = ContextHelpers.FlattenLoadedContext(contextByIdentity);

            GetRuleValue getRuleValue = null;
            GetContextValue recursiveContext = key =>
            {
                if (key.StartsWith("@@key")){
                    key = key.Replace("@@key", "keys.");
                }
                if (!key.StartsWith("keys.")) return Option<JsonValue>.None;
                var path = new ConfigurationPath(key.Split('.')[1]);
                return getRuleValue(path).Map(x => x.Value);
            };

            var context = ContextHelpers.Merge(flattenContext, recursiveContext);

            getRuleValue = Memoize(path =>
            {
                foreach (var identity in identityTypes)
                {
                    var fixedResult = ContextHelpers.GetFixedConfigurationContext(context, identity)(path);<commit_msg>fix check<commit_after>﻿using System.Collections.Generic;
using System.Linq;
using Engine.Core.Context;
using Engine.Core.Rules;
using LanguageExt;
using Engine.Core.Utils;
using Engine.DataTypes;
using FSharpUtils.Newtonsoft;

namespace Engine.Core
{
    public delegate Option<IRule> RulesRepository(ConfigurationPath path);


    public static class EngineCore
    {
        public delegate Option<ConfigurationValue> GetRuleValue(ConfigurationPath path);

        public static GetRuleValue GetRulesEvaluator(HashSet<Identity> identities, GetLoadedContextByIdentityType contextByIdentity, RulesRepository rules)
        {
            var identityTypes = identities.Select(x => x.Type).ToArray();
            var flattenContext = ContextHelpers.FlattenLoadedContext(contextByIdentity);

            GetRuleValue getRuleValue = null;
            GetContextValue recursiveContext = key =>
            {
                if (key.StartsWith("@@key:")){
                    key = key.Replace("@@key:", "keys.");
                }
                if (!key.StartsWith("keys.")) return Option<JsonValue>.None;
                var path = new ConfigurationPath(key.Split('.')[1]);
                return getRuleValue(path).Map(x => x.Value);
            };

            var context = ContextHelpers.Merge(flattenContext, recursiveContext);

            getRuleValue = Memoize(path =>
            {
                foreach (var identity in identityTypes)
                {
                    var fixedResult = ContextHelpers.GetFixedConfigurationContext(context, identity)(path);
{'fraction_non_alphanumeric': 0.09414758269720101, 'fraction_numerical': 0.0006361323155216285, 'mean_word_length': 2.5983981693363845, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5374776', 'n_tokens_mistral': 782, 'n_tokens_neox': 751, 'n_words': 170}