class Licensee::Matchers::Dice

Public Instance Methods

confidence() click to toggle source

Confidence that the matched license is a match

# File lib/licensee/matchers/dice.rb, line 53
def confidence
  @confidence ||= match ? match.similarity(file) : 0
end
licenses_by_similarity()
match() click to toggle source

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

# File lib/licensee/matchers/dice.rb, line 8
def match
  @match ||= if matches.empty?
               nil
             else
               matches.first[0]
  end
end
matches() click to toggle source
# File lib/licensee/matchers/dice.rb, line 46
def matches
  @matches ||= matches_by_similarity.select do |_, similarity|
    similarity >= minimum_confidence
  end
end
matches_by_similarity() click to toggle source
# File lib/licensee/matchers/dice.rb, line 36
def matches_by_similarity
  @matches_by_similarity ||= begin
    matches = potential_matches.map do |potential_match|
      [potential_match, potential_match.similarity(file)]
    end
    matches.sort_by { |_, similarity| similarity }.reverse
  end
end
Also aliased as: licenses_by_similarity
potential_licenses()
Alias for: potential_matches
potential_matches() 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.rb, line 23
def potential_matches
  @potential_matches ||= begin
    super.select do |license|
      if license.creative_commons? && file.potential_false_positive?
        false
      else
        license.wordset
      end
    end
  end
end
Also aliased as: potential_licenses

Private Instance Methods

minimum_confidence() click to toggle source
# File lib/licensee/matchers/dice.rb, line 59
def minimum_confidence
  Licensee.confidence_threshold
end