Class: Licensee::Matchers::Dice
- Defined in:
- lib/licensee/matchers/dice.rb
Constant Summary
Constants inherited from Matcher
Instance Attribute Summary
Attributes inherited from Matcher
Instance Method Summary collapse
-
#confidence ⇒ Object
Confidence that the matched license is a match.
-
#match ⇒ Object
Return the first potential license that is more similar than the confidence threshold.
- #matches ⇒ Object
- #matches_by_similarity ⇒ Object (also: #licenses_by_similarity)
-
#potential_matches ⇒ Object
(also: #potential_licenses)
Licenses that may be a match for this file.
Methods inherited from Matcher
Methods included from HashHelper
Constructor Details
This class inherits a constructor from Licensee::Matchers::Matcher
Instance Method Details
#confidence ⇒ Object
Confidence that the matched license is a match
51 52 53 |
# File 'lib/licensee/matchers/dice.rb', line 51 def confidence @confidence ||= match ? match.similarity(file) : 0 end |
#match ⇒ Object
Return the first potential license that is more similar than the confidence threshold
8 9 10 11 12 13 14 |
# File 'lib/licensee/matchers/dice.rb', line 8 def match @match ||= if matches.empty? nil else matches.first[0] end end |
#matches ⇒ Object
44 45 46 47 48 |
# File 'lib/licensee/matchers/dice.rb', line 44 def matches @matches ||= matches_by_similarity.select do |_, similarity| similarity >= minimum_confidence end end |
#matches_by_similarity ⇒ Object Also known as: licenses_by_similarity
34 35 36 37 38 39 40 41 |
# File 'lib/licensee/matchers/dice.rb', line 34 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 |
#potential_matches ⇒ Object Also known as: potential_licenses
Licenses that may be a match for this file. To avoid false positives:
-
Creative commons licenses cannot be matched against license files that begin with the title of a non-open source CC license variant
-
The percentage change in file length may not exceed the inverse of the confidence threshold
23 24 25 26 27 28 29 30 31 |
# File 'lib/licensee/matchers/dice.rb', line 23 def potential_matches @potential_matches ||= super.select do |license| if license.creative_commons? && file.potential_false_positive? false else license.wordset end end end |