<commit_before>module ModelKit
    module Component
        module Loaders
            # Definition of the base loader API
            class Base
                # Projects loaded so far
                #
                # @return [Hash<String,Project>]
                attr_reader :loaded_projects

                # Set of typekits loaded so far
                #
                # @return [Hash<String,Typekit>]
                attr_reader :loaded_typekits

                # Node models loaded so far
                #
                # @return [Hash<String,Node>]
                attr_reader :loaded_node_models

                # Deployment models loaded so far
                #
                # @return [Hash<String,Deployment>]
                attr_reader :loaded_deployment_models

                # All types loaded so far
                #
                # @return [ModelKit::Types::Registry]
                attr_reader :registry

                # The set of types that can be used on component interfaces
                # among the types loaded so far
                attr_reader :interface_types

                # A mapping from type names to the typekits that define them
                #
                # @return [Hash<String,Set<Typekit>>]
                attr_reader :typekits_by_type_name

                # The loader that should be used to resolve dependencies
                attr_reader :root_loader

                # Set of callbacks that are called whenever a new project gets
                # loaded
                #
                # @return [Array<#call>]
                attr_reader :project_load_callbacks

                # Set of callbacks that are called whenever a new typekit gets
                # loaded
                #
                # @return [Array<#call>]
                attr_reader :typekit_load_callbacks

                def initialize(root_loader = self)
                    @root_loader = root_loader
                    if root_loader != self
                        root_loader.added_child(self)
                    end
                    @typekit_load_callbacks = Array.new
                    @project_load_callbacks = Array.new
                    clear
                end

                def clear
                    @interface_types = Set.new
                    @loaded_projects = Hash.new
                    @loaded_typekits = Hash.new
                    @loaded_node_models = Hash.new
                    @loaded_deployment_models = Hash.new
                    @typekits_by_type_name = Hash.new
                    @registry = Types::Registry.new
                    registry.create_null '/modelkit/component/void'
                end

                # Hook called when this loader is used as a root loader on
                # another loader
                #
                # @param [Base] loader the loader that will use self as root
                def added_child(loader)
                end

                # Parse a textual representation of a project into a {Project}
                # object
                #
                # The default is to evaluate the text in the project's object
                # context
                #
                # @param [Project] project the project that is being set up by
                #   the text
                # @param [Project] project the project that is being set up by
                #   the text
                def parse_project_text(text, path: nil)
                    project = Project.new(root_loader)
                    if !path
                        project.instance_eval text
                    else
                        project.instance_eval text, path, 1
                    end
                    project
                end

                # Returns the project model corresponding to the given name
                #
                # @param [String] the project name
                # @raise [ProjectNotFound] if there is no project with that
                #   name.
                # @return [ModelKit::Component::Project]
                def project_model_from_name(name)
                    name = name.to_str
                    if project = loaded_projects[name]
                        return project
                    end

                    text, path = project_model_text_from_name(name)

                    Component.info "loading project #{name}"
                    project = parse_project_text(text, path: path)
                    project.typekit = typekit_model_from_name(name)
                    if project.name != name
                        raise InternalError, "inconsistency: got project #{project.name} while loading #{name}"
                    end
                    register_project_model(project)
                    project
                end
                
                # Registers this project's subobjects (node models and
                # deployment models)
                def register_project_model(project)
                    if loaded_projects.has_key?(project.name)
                        raise AlreadyRegistered, "there is already a project called #{project.name} registered on #{self}"
                    end

                    loaded_projects[project.name] = project
                    if root_loader != self
                        return root_loader.register_project_model(project)
                    end

                    project.each_node_model do |node_model|
                        register_node_model(node_model)
                    end
                    project.each_deployment_model do |deployment_model|
                        register_deployment_model(deployment_model)
                    end
                    project_load_callbacks.each do |callback|
                        callback.call(project)
                    end
                end

                # Registers a callback that should be called with newly registered
                # projects
                #
                # @param [Boolean] initial_events if true, the callbacks will be
                #   called instantly with the projects that have already been loaded
                def on_project_load(initial_events: true, &block)
                    project_load_callbacks << block
                    if initial_events
                        current_set = loaded_projects.values.dup
                        current_set.each do |p|
                            block.call(p)
                        end
                    end
                    block
                end

                # Removes the given callback from the listeners to {on_project_load}
                #
                # @param [Object] callback the value returned by {on_project_load}
                #   for the callback that should be removed
                def remove_project_load_callback(callback)
                    project_load_callbacks.delete(callback)
                end

                # Whether a project with this name is already loaded
                #
                # @param [String] name the name of the project to test for
                def has_loaded_project?(name)
                    loaded_projects.has_key?(name)
                end

                def parse_typekit_text(text, path: path)
                    metainfo = YAML.load(text)
                    if xml_section_index = (text =~ /<typelib>/)
                        xml_section = text[xml_section_index..-1]
                    else
                        raise ArgumentError, "given text does not contain a modelkit-types XML section"
                    end


                    registry = Types::Registry.from_xml(REXML::Document.new(xml_section))
<commit_msg>loaders: fix another self-reference in keyword arguments<commit_after>module ModelKit
    module Component
        module Loaders
            # Definition of the base loader API
            class Base
                # Projects loaded so far
                #
                # @return [Hash<String,Project>]
                attr_reader :loaded_projects

                # Set of typekits loaded so far
                #
                # @return [Hash<String,Typekit>]
                attr_reader :loaded_typekits

                # Node models loaded so far
                #
                # @return [Hash<String,Node>]
                attr_reader :loaded_node_models

                # Deployment models loaded so far
                #
                # @return [Hash<String,Deployment>]
                attr_reader :loaded_deployment_models

                # All types loaded so far
                #
                # @return [ModelKit::Types::Registry]
                attr_reader :registry

                # The set of types that can be used on component interfaces
                # among the types loaded so far
                attr_reader :interface_types

                # A mapping from type names to the typekits that define them
                #
                # @return [Hash<String,Set<Typekit>>]
                attr_reader :typekits_by_type_name

                # The loader that should be used to resolve dependencies
                attr_reader :root_loader

                # Set of callbacks that are called whenever a new project gets
                # loaded
                #
                # @return [Array<#call>]
                attr_reader :project_load_callbacks

                # Set of callbacks that are called whenever a new typekit gets
                # loaded
                #
                # @return [Array<#call>]
                attr_reader :typekit_load_callbacks

                def initialize(root_loader = self)
                    @root_loader = root_loader
                    if root_loader != self
                        root_loader.added_child(self)
                    end
                    @typekit_load_callbacks = Array.new
                    @project_load_callbacks = Array.new
                    clear
                end

                def clear
                    @interface_types = Set.new
                    @loaded_projects = Hash.new
                    @loaded_typekits = Hash.new
                    @loaded_node_models = Hash.new
                    @loaded_deployment_models = Hash.new
                    @typekits_by_type_name = Hash.new
                    @registry = Types::Registry.new
                    registry.create_null '/modelkit/component/void'
                end

                # Hook called when this loader is used as a root loader on
                # another loader
                #
                # @param [Base] loader the loader that will use self as root
                def added_child(loader)
                end

                # Parse a textual representation of a project into a {Project}
                # object
                #
                # The default is to evaluate the text in the project's object
                # context
                #
                # @param [Project] project the project that is being set up by
                #   the text
                # @param [Project] project the project that is being set up by
                #   the text
                def parse_project_text(text, path: nil)
                    project = Project.new(root_loader)
                    if !path
                        project.instance_eval text
                    else
                        project.instance_eval text, path, 1
                    end
                    project
                end

                # Returns the project model corresponding to the given name
                #
                # @param [String] the project name
                # @raise [ProjectNotFound] if there is no project with that
                #   name.
                # @return [ModelKit::Component::Project]
                def project_model_from_name(name)
                    name = name.to_str
                    if project = loaded_projects[name]
                        return project
                    end

                    text, path = project_model_text_from_name(name)

                    Component.info "loading project #{name}"
                    project = parse_project_text(text, path: path)
                    project.typekit = typekit_model_from_name(name)
                    if project.name != name
                        raise InternalError, "inconsistency: got project #{project.name} while loading #{name}"
                    end
                    register_project_model(project)
                    project
                end
                
                # Registers this project's subobjects (node models and
                # deployment models)
                def register_project_model(project)
                    if loaded_projects.has_key?(project.name)
                        raise AlreadyRegistered, "there is already a project called #{project.name} registered on #{self}"
                    end

                    loaded_projects[project.name] = project
                    if root_loader != self
                        return root_loader.register_project_model(project)
                    end

                    project.each_node_model do |node_model|
                        register_node_model(node_model)
                    end
                    project.each_deployment_model do |deployment_model|
                        register_deployment_model(deployment_model)
                    end
                    project_load_callbacks.each do |callback|
                        callback.call(project)
                    end
                end

                # Registers a callback that should be called with newly registered
                # projects
                #
                # @param [Boolean] initial_events if true, the callbacks will be
                #   called instantly with the projects that have already been loaded
                def on_project_load(initial_events: true, &block)
                    project_load_callbacks << block
                    if initial_events
                        current_set = loaded_projects.values.dup
                        current_set.each do |p|
                            block.call(p)
                        end
                    end
                    block
                end

                # Removes the given callback from the listeners to {on_project_load}
                #
                # @param [Object] callback the value returned by {on_project_load}
                #   for the callback that should be removed
                def remove_project_load_callback(callback)
                    project_load_callbacks.delete(callback)
                end

                # Whether a project with this name is already loaded
                #
                # @param [String] name the name of the project to test for
                def has_loaded_project?(name)
                    loaded_projects.has_key?(name)
                end

                def parse_typekit_text(text, path: nil)
                    metainfo = YAML.load(text)
                    if xml_section_index = (text =~ /<typelib>/)
                        xml_section = text[xml_section_index..-1]
                    else
                        raise ArgumentError, "given text does not contain a modelkit-types XML section"
                    end


                    registry = Types::Registry.from_xml(REXML::Document.new(xml_section))

{'fraction_non_alphanumeric': 0.04913183279742765, 'fraction_numerical': 0.0002572347266881029, 'mean_word_length': 1.1373007146783947, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '2873700', 'n_tokens_mistral': 3599, 'n_tokens_neox': 3206, 'n_words': 1022}