Class: Winnow::Fingerprinter

Inherits:
Object
  • Object
show all
Defined in:
lib/winnow/fingerprinter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#guaranteeObject (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

#noiseObject (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

#preprocessorObject (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