class Licensee::Matchers::Dice

Attributes

file[R]

Public Class Methods

new(file) click to toggle source
# File lib/licensee/matchers/dice_matcher.rb, line 6
def initialize(file)
  @file = file
end

Public Instance Methods

confidence() click to toggle source

Confidence that the matched license is a match

# File lib/licensee/matchers/dice_matcher.rb, line 55
def confidence
  @confidence ||= match ? file.similarity(match) : 0
end
licenses_by_similiarity() click to toggle source
# File lib/licensee/matchers/dice_matcher.rb, line 39
def licenses_by_similiarity
  @licenses_by_similiarity ||= begin
    licenses = potential_licenses.map do |license|
      [license, license.similarity(file)]
    end
    licenses.sort_by { |_, similarity| similarity }.reverse
  end
end
match() click to toggle source

Return the first potential license that is more similar than the confidence threshold

# File lib/licensee/matchers/dice_matcher.rb, line 12
def match
  @match ||= if matches.empty?
    nil
  else
    matches.first[0]
  end
end
matches() click to toggle source
# File lib/licensee/matchers/dice_matcher.rb, line 48
def matches
  @matches ||= licenses_by_similiarity.select do |_, similarity|
    similarity >= Licensee.confidence_threshold
  end
end
potential_licenses() click to toggle source

Licenses that may be a match for this file. To avoid false positives:

  1. Creative commons licenses cannot be matched against license files that begin with the title of a non-open source CC license variant

  2. The percentage change in file length may not exceed the inverse of the confidence threshold

# File lib/licensee/matchers/dice_matcher.rb, line 27
def potential_licenses
  @potential_licenses ||= begin
    Licensee.licenses(hidden: true).select do |license|
      if license.creative_commons? && file.potential_false_positive?
        false
      else
        license.wordset && license.length_delta(file) <= license.max_delta
      end
    end
  end
end