<commit_before>module KnifeCookbookReadme
  class ResourceModel

    attr_reader :native_resource

    def initialize(cookbook_name, file)
      @native_resource = build_native_from_file(cookbook_name, file)
      load_descriptions
    end

    def name
      @native_resource.resource_name
    end

    # Return the unique set of actions, with the default one first, if there is a default
    def actions
      unless @actions
        @actions = [default_action].compact + @native_resource.actions.sort.uniq.select { |a| a != default_action }
      end
      @actions
    end

    def default_action
      @native_resource.default_action
    end

    def action_description(action)
      action_descriptions[action.to_s]
    end

    def action_descriptions
      @action_descriptions ||= {}
    end

    def attributes
      @native_resource.attribute_specifications.keys
    end

    def attribute_description(attribute)
      attribute_descriptions[attribute.to_s]
    end

    def attribute_has_default_value?(attribute)
      specification = @native_resource.attribute_specifications[attribute]
      specification && specification.has_key?(:default)
    end

    def attribute_default_value(attribute)
      if attribute_has_default_value?(attribute)
        return @native_resource.attribute_specifications[attribute][:default]
      else
        return nil
      end
    end

    def attribute_descriptions
      @attribute_descriptions ||= {}
    end

    def short_description
      unless @short_description
        @short_description = first_sentence(top_level_description('main'))
      end
      @short_description
    end

    def first_sentence(string)
      string.gsub(/^([^\.]*)./, '\1').strip
    end

    def top_level_description(section)
      (top_level_descriptions[section.to_s] || []).join("\n").gsub(/\n+$/m,"\n")
    end

    def top_level_descriptions
      @top_level_descriptions ||= {}
    end

    private

    def load_descriptions
      current_section = 'main'<commit_msg>Fix the mechanism for getting the first sentence<commit_after>module KnifeCookbookReadme
  class ResourceModel

    attr_reader :native_resource

    def initialize(cookbook_name, file)
      @native_resource = build_native_from_file(cookbook_name, file)
      load_descriptions
    end

    def name
      @native_resource.resource_name
    end

    # Return the unique set of actions, with the default one first, if there is a default
    def actions
      unless @actions
        @actions = [default_action].compact + @native_resource.actions.sort.uniq.select { |a| a != default_action }
      end
      @actions
    end

    def default_action
      @native_resource.default_action
    end

    def action_description(action)
      action_descriptions[action.to_s]
    end

    def action_descriptions
      @action_descriptions ||= {}
    end

    def attributes
      @native_resource.attribute_specifications.keys
    end

    def attribute_description(attribute)
      attribute_descriptions[attribute.to_s]
    end

    def attribute_has_default_value?(attribute)
      specification = @native_resource.attribute_specifications[attribute]
      specification && specification.has_key?(:default)
    end

    def attribute_default_value(attribute)
      if attribute_has_default_value?(attribute)
        return @native_resource.attribute_specifications[attribute][:default]
      else
        return nil
      end
    end

    def attribute_descriptions
      @attribute_descriptions ||= {}
    end

    def short_description
      unless @short_description
        @short_description = first_sentence(top_level_description('main'))
      end
      @short_description
    end

    def first_sentence(string)
      string.gsub(/^([^.]*?\.)/m) do |match|
        return $1.gsub("\n",' ').strip
      end
      return nil
    end

    def top_level_description(section)
      (top_level_descriptions[section.to_s] || []).join("\n").gsub(/\n+$/m,"\n")
    end

    def top_level_descriptions
      @top_level_descriptions ||= {}
    end

    private

    def load_descriptions
      current_section = 'main'
{'fraction_non_alphanumeric': 0.07981562348374575, 'fraction_numerical': 0.00048520135856380397, 'mean_word_length': 3.0107003891050583, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4218809', 'n_tokens_mistral': 1203, 'n_tokens_neox': 1156, 'n_words': 247}