<commit_before># -*- coding: utf-8 -*-


import os

from openfisca_core import decompositions, reforms


# Declarations, initialized in environment module

build_reform_function_by_key = None
decomposition_json_by_file_path_cache = {}
input_variables_and_parameters_by_column_name_cache = {}
input_variables_extractor = None
parameters_json_cache = None
reform_by_full_key = None
tax_benefit_system = None
TaxBenefitSystem = None


def get_cached_composed_reform(reform_keys, tax_benefit_system):
    full_key = '.'.join(
        [tax_benefit_system.full_key] + reform_keys
        if isinstance(tax_benefit_system, reforms.AbstractReform)
        else reform_keys
        )
    composed_reform = reform_by_full_key.get(full_key)
    if composed_reform is None:
        build_reform_functions = [build_reform_function_by_key[reform_key] for reform_key in reform_keys]
        composed_reform = reforms.compose_reforms(
            build_functions_and_keys = zip(build_reform_functions, reform_keys),
            tax_benefit_system = tax_benefit_system,
            )
        assert full_key == composed_reform.full_key
        reform_by_full_key[full_key] = composed_reform
    return composed_reform


def get_cached_or_new_decomposition_json(tax_benefit_system, xml_file_name = None):
    if xml_file_name is None:
        xml_file_name = tax_benefit_system.DEFAULT_DECOMP_FILE<commit_msg>Raise exception when calling reforms without loading any<commit_after># -*- coding: utf-8 -*-


import os

from openfisca_core import decompositions, reforms


# Declarations, initialized in environment module

build_reform_function_by_key = None
decomposition_json_by_file_path_cache = {}
input_variables_and_parameters_by_column_name_cache = {}
input_variables_extractor = None
parameters_json_cache = None
reform_by_full_key = None
tax_benefit_system = None
TaxBenefitSystem = None


def get_cached_composed_reform(reform_keys, tax_benefit_system):
    if reform_by_full_key is None:
        raise Exception('Cannot use reforms when none has been loaded in the instance configuration')\

    full_key = '.'.join(
        [tax_benefit_system.full_key] + reform_keys
        if isinstance(tax_benefit_system, reforms.AbstractReform)
        else reform_keys
        )
    composed_reform = reform_by_full_key.get(full_key)
    if composed_reform is None:
        build_reform_functions = [build_reform_function_by_key[reform_key] for reform_key in reform_keys]
        composed_reform = reforms.compose_reforms(
            build_functions_and_keys = zip(build_reform_functions, reform_keys),
            tax_benefit_system = tax_benefit_system,
            )
        assert full_key == composed_reform.full_key
        reform_by_full_key[full_key] = composed_reform
    return composed_reform


def get_cached_or_new_decomposition_json(tax_benefit_system, xml_file_name = None):
    if xml_file_name is None:
        xml_file_name = tax_benefit_system.DEFAULT_DECOMP_FILE
{'fraction_non_alphanumeric': 0.05668016194331984, 'fraction_numerical': 0.0006747638326585695, 'mean_word_length': 4.440366972477064, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '3278010', 'n_tokens_mistral': 970, 'n_tokens_neox': 935, 'n_words': 177}