Class: Simhilarity::Element
- Inherits:
-
Object
- Object
- Simhilarity::Element
- 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
-
#matcher ⇒ Object
readonly
matcher that owns this guy.
-
#opaque ⇒ Object
readonly
opaque object from the user.
Instance Method Summary collapse
-
#initialize(matcher, opaque) ⇒ Element
constructor
:nodoc:.
-
#inspect ⇒ Object
:nodoc:.
-
#ngrams ⇒ Object
List of ngrams generated from
str
via Matcher#ngrams. -
#ngrams_sum ⇒ Object
Weighted frequency sum of
ngrams
via Matcher#ngrams_sum. -
#simhash ⇒ Object
Weighted simhash of
ngrams
via Matcher#simhash. -
#str ⇒ Object
Text string generated from
opaque
via Matcher#read. -
#to_s ⇒ Object
:nodoc:.
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
#matcher ⇒ Object (readonly)
matcher that owns this guy
8 9 10 |
# File 'lib/simhilarity/element.rb', line 8 def matcher @matcher end |
#opaque ⇒ Object (readonly)
opaque object from the user
11 12 13 |
# File 'lib/simhilarity/element.rb', line 11 def opaque @opaque end |
Instance Method Details
#inspect ⇒ Object
:nodoc:
46 47 48 |
# File 'lib/simhilarity/element.rb', line 46 def inspect #:nodoc: str.inspect end |
#ngrams ⇒ Object
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_sum ⇒ Object
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 |
#simhash ⇒ Object
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 |
#str ⇒ Object
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_s ⇒ Object
:nodoc:
42 43 44 |
# File 'lib/simhilarity/element.rb', line 42 def to_s #:nodoc: str end |