<commit_before>require 'rugged'

module Licensee
  class Project
    attr_reader :detect_readme, :detect_packages
    alias detect_readme? detect_readme
    alias detect_packages? detect_packages

    def initialize(detect_packages: false, detect_readme: false)
      @detect_packages = detect_packages
      @detect_readme = detect_readme
    end

    # Returns the matching License instance if a license can be detected
    def license
      @license ||= matched_file && matched_file.license
    end

    def matched_file
      @matched_file ||= (license_file || readme || package_file)
    end

    def license_file
      return @license_file if defined? @license_file
      @license_file = begin
        license_file = license_from_file { |n| LicenseFile.name_score(n) }
        return license_file unless license_file && license_file.license

        # Special case LGPL, which actuall lives in LICENSE.lesser, per the
        # license instructions. See https://git.io/viwyK
        lesser = if license_file.license.gpl?
          license_from_file { |file| LicenseFile.lesser_gpl_score(file) }
        end

        lesser || license_file
      end
    end

    def readme_file
      return unless detect_readme?
      return @readme if defined? @readme<commit_msg>project: Fix a minor typo in a comment<commit_after>require 'rugged'

module Licensee
  class Project
    attr_reader :detect_readme, :detect_packages
    alias detect_readme? detect_readme
    alias detect_packages? detect_packages

    def initialize(detect_packages: false, detect_readme: false)
      @detect_packages = detect_packages
      @detect_readme = detect_readme
    end

    # Returns the matching License instance if a license can be detected
    def license
      @license ||= matched_file && matched_file.license
    end

    def matched_file
      @matched_file ||= (license_file || readme || package_file)
    end

    def license_file
      return @license_file if defined? @license_file
      @license_file = begin
        license_file = license_from_file { |n| LicenseFile.name_score(n) }
        return license_file unless license_file && license_file.license

        # Special case LGPL, which actually lives in LICENSE.lesser, per the
        # license instructions. See https://git.io/viwyK
        lesser = if license_file.license.gpl?
          license_from_file { |file| LicenseFile.lesser_gpl_score(file) }
        end

        lesser || license_file
      end
    end

    def readme_file
      return unless detect_readme?
      return @readme if defined? @readme
{'fraction_non_alphanumeric': 0.06347352024922118, 'fraction_numerical': 0.0, 'mean_word_length': 3.039308176100629, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '4404481', 'n_tokens_mistral': 734, 'n_tokens_neox': 720, 'n_words': 210}