Class: Winnow::Fingerprinter
- Inherits:
-
Object
- Object
- Winnow::Fingerprinter
- Defined in:
- lib/winnow/fingerprinter.rb
Instance Attribute Summary collapse
-
#guarantee ⇒ Object
(also: #guarantee_threshold)
readonly
Returns the value of attribute guarantee.
-
#noise ⇒ Object
(also: #noise_threshold)
readonly
Returns the value of attribute noise.
-
#preprocessor ⇒ Object
readonly
Returns the value of attribute preprocessor.
Instance Method Summary collapse
- #fingerprints(str, params = {}) ⇒ Object
-
#initialize(params) ⇒ Fingerprinter
constructor
A new instance of Fingerprinter.
Constructor Details
#initialize(params) ⇒ Fingerprinter
Returns a new instance of Fingerprinter.
7 8 9 10 11 |
# File 'lib/winnow/fingerprinter.rb', line 7 def initialize(params) @guarantee = params[:guarantee_threshold] || params[:t] @noise = params[:noise_threshold] || params[:k] @preprocessor = params[:preprocessor] || Preprocessors::Plaintext.new end |
Instance Attribute Details
#guarantee ⇒ Object (readonly) Also known as: guarantee_threshold
Returns the value of attribute guarantee.
3 4 5 |
# File 'lib/winnow/fingerprinter.rb', line 3 def guarantee @guarantee end |
#noise ⇒ Object (readonly) Also known as: noise_threshold
Returns the value of attribute noise.
3 4 5 |
# File 'lib/winnow/fingerprinter.rb', line 3 def noise @noise end |
#preprocessor ⇒ Object (readonly)
Returns the value of attribute preprocessor.
3 4 5 |
# File 'lib/winnow/fingerprinter.rb', line 3 def preprocessor @preprocessor end |
Instance Method Details
#fingerprints(str, params = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/winnow/fingerprinter.rb', line 13 def fingerprints(str, params = {}) source = params[:source] fingerprints = {} windows(str, source).each do |window| least_fingerprint = window.min_by { |fingerprint| fingerprint[:value] } value = least_fingerprint[:value] location = least_fingerprint[:location] (fingerprints[value] ||= []) << location end fingerprints end |