Class: Simhilarity::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/simhilarity/element.rb

Overview

Internal wrapper around opaque items from user. This mostly exists to cache stuff that’s expensive, like the ngrams.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(matcher, opaque) ⇒ Element

:nodoc:



13
14
15
16
# File 'lib/simhilarity/element.rb', line 13

def initialize(matcher, opaque) #:nodoc:
  @matcher = matcher
  @opaque = opaque
end

Instance Attribute Details

#matcherObject (readonly)

matcher that owns this guy



8
9
10
# File 'lib/simhilarity/element.rb', line 8

def matcher
  @matcher
end

#opaqueObject (readonly)

opaque object from the user



11
12
13
# File 'lib/simhilarity/element.rb', line 11

def opaque
  @opaque
end

Instance Method Details

#inspectObject

:nodoc:



46
47
48
# File 'lib/simhilarity/element.rb', line 46

def inspect #:nodoc:
  str.inspect
end

#ngramsObject

List of ngrams generated from str via Matcher#ngrams. Lazily calculated.



26
27
28
# File 'lib/simhilarity/element.rb', line 26

def ngrams
  @ngrams ||= matcher.ngrams(str)
end

#ngrams_sumObject

Weighted frequency sum of ngrams via Matcher#ngrams_sum. Lazily calculated.



32
33
34
# File 'lib/simhilarity/element.rb', line 32

def ngrams_sum
  @ngrams_sum ||= matcher.ngrams_sum(ngrams)
end

#simhashObject

Weighted simhash of ngrams via Matcher#simhash. Lazily calculated.



38
39
40
# File 'lib/simhilarity/element.rb', line 38

def simhash
  @simhash ||= matcher.simhash(ngrams)
end

#strObject

Text string generated from opaque via Matcher#read. Lazily calculated.



20
21
22
# File 'lib/simhilarity/element.rb', line 20

def str
  @str ||= matcher.normalize(matcher.read(opaque))
end

#to_sObject

:nodoc:



42
43
44
# File 'lib/simhilarity/element.rb', line 42

def to_s #:nodoc:
  str
end