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

            # Set of task models that are known to us
            attr_reader :loaded_task_models

            # Set of deployment models that are known to us
            attr_reader :loaded_deployment_models

            # The registry that includes types from all loaded typekits
            attr_reader :registry

            # The list of types that can be used on an oroGen interface
            attr_reader :interface_typelist

            # A mapping from type names to the typekits that define them
            attr_reader :typekits_by_type_name

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

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

            # Sets the behaviour of the type resolution on unknown types
            #
            # @return [Boolean]
            attr_predicate :define_dummy_types?, true

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

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

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

            def clear
                @loaded_projects = Hash.new
                @loaded_typekits = Hash.new
                @loaded_task_models = Hash.new
                @loaded_deployment_models = Hash.new
                @typekits_by_type_name = Hash.new
                @registry = Typelib::Registry.new
                @interface_typelist = Set.new
            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 [OroGen::Spec::Project]
            def project_model_from_name(name)
                if project = loaded_projects[name]
                    return project
                end

                name = name.to_str

                text, path = project_model_text_from_name(name)

                OroGen.info "loading oroGen project #{name}"
                project = Spec::Project.new(root_loader)
                project.typekit =
                    if has_typekit?(name)
                        typekit_model_from_name(name)
                    else
                        Spec::Typekit.new(root_loader, name)
                    end

                Loaders::Project.new(project).__eval__(path, text)
                register_project_model(project)
                project
            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
            end

            # Returns the task library model corresponding to the given name
            # @param (see project_model_from_name)
            # @raise [ProjectNotFound] if there is no task library with that
            #   name. This does including having a project with that name if the
            #   project defines no tasks.
            # @return (see project_model_from_name)
            def task_library_model_from_name(name)
                project = project_model_from_name(name)
                if project.self_tasks.empty?
                    raise ProjectNotFound, "there is an oroGen project called #{name}, but it defines no tasks"
                end
                project
            end

            # Returns the task model object corresponding to a model name
            #
            # @param [String] name the task model name
            # @return [Spec::TaskContext]
            # @raise [TaskModelNotFound] if there are no such model
            # @raise (see project_model_from_name)
            def task_model_from_name(name)
                if model = loaded_task_models[name]
                    return model
                end<commit_msg>allow to remove project load callbacks<commit_after>module OroGen
    module Loaders
        # Definition of the base loader API
        class Base
            # Set of projects loaded so far
            #
            # @return [Hash<String,Spec::Project>]
            attr_reader :loaded_projects

            # Set of task models that are known to us
            attr_reader :loaded_task_models

            # Set of deployment models that are known to us
            attr_reader :loaded_deployment_models

            # The registry that includes types from all loaded typekits
            attr_reader :registry

            # The list of types that can be used on an oroGen interface
            attr_reader :interface_typelist

            # A mapping from type names to the typekits that define them
            attr_reader :typekits_by_type_name

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

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

            # Sets the behaviour of the type resolution on unknown types
            #
            # @return [Boolean]
            attr_predicate :define_dummy_types?, true

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

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

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

            def clear
                @loaded_projects = Hash.new
                @loaded_typekits = Hash.new
                @loaded_task_models = Hash.new
                @loaded_deployment_models = Hash.new
                @typekits_by_type_name = Hash.new
                @registry = Typelib::Registry.new
                @interface_typelist = Set.new
            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 [OroGen::Spec::Project]
            def project_model_from_name(name)
                if project = loaded_projects[name]
                    return project
                end

                name = name.to_str

                text, path = project_model_text_from_name(name)

                OroGen.info "loading oroGen project #{name}"
                project = Spec::Project.new(root_loader)
                project.typekit =
                    if has_typekit?(name)
                        typekit_model_from_name(name)
                    else
                        Spec::Typekit.new(root_loader, name)
                    end

                Loaders::Project.new(project).__eval__(path, text)
                register_project_model(project)
                project
            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

            # Returns the task library model corresponding to the given name
            # @param (see project_model_from_name)
            # @raise [ProjectNotFound] if there is no task library with that
            #   name. This does including having a project with that name if the
            #   project defines no tasks.
            # @return (see project_model_from_name)
            def task_library_model_from_name(name)
                project = project_model_from_name(name)
                if project.self_tasks.empty?
                    raise ProjectNotFound, "there is an oroGen project called #{name}, but it defines no tasks"
                end
                project
            end

            # Returns the task model object corresponding to a model name
            #
            # @param [String] name the task model name
            # @return [Spec::TaskContext]
            # @raise [TaskModelNotFound] if there are no such model
            # @raise (see project_model_from_name)
            def task_model_from_name(name)
                if model = loaded_task_models[name]
                    return model
                end
{'fraction_non_alphanumeric': 0.04948531494947587, 'fraction_numerical': 0.0, 'mean_word_length': 1.4508215690812312, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, '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': '2943217', 'n_tokens_mistral': 2547, 'n_tokens_neox': 2411, 'n_words': 807}