Class: ClassifierReborn::CachedContentNode

Inherits:
ContentNode
  • Object
show all
Defined in:
lib/classifier-reborn/lsi/cached_content_node.rb

Overview

Subclass of ContentNode which caches the search_vector transpositions. Its great because its much faster for large indexes, but at the cost of more ram. Additionally, if you Marshal your classifier and want to keep the size down, you’ll need to manually clear the cache before you dump

Defined Under Namespace

Modules: InstanceMethods

Instance Attribute Summary

Attributes inherited from ContentNode

#categories, #lsi_norm, #lsi_vector, #raw_norm, #raw_vector, #word_hash

Instance Method Summary collapse

Methods inherited from ContentNode

#search_norm, #search_vector

Constructor Details

#initialize(word_hash, *categories) ⇒ CachedContentNode

Returns a new instance of CachedContentNode.



20
21
22
23
# File 'lib/classifier-reborn/lsi/cached_content_node.rb', line 20

def initialize(word_hash, *categories)
  clear_cache!
  super
end

Instance Method Details

#clear_cache!Object



25
26
27
# File 'lib/classifier-reborn/lsi/cached_content_node.rb', line 25

def clear_cache!
  @transposed_search_vector = nil
end

#marshal_dumpObject

We don’t want the cached_data here



41
42
43
# File 'lib/classifier-reborn/lsi/cached_content_node.rb', line 41

def marshal_dump
  [@lsi_vector, @lsi_norm, @raw_vector, @raw_norm, @categories, @word_hash]
end

#marshal_load(array) ⇒ Object



45
46
47
# File 'lib/classifier-reborn/lsi/cached_content_node.rb', line 45

def marshal_load(array)
  @lsi_vector, @lsi_norm, @raw_vector, @raw_norm, @categories, @word_hash = array
end

#raw_vector_with(word_list) ⇒ Object

Clear the cache before we continue on



35
36
37
38
# File 'lib/classifier-reborn/lsi/cached_content_node.rb', line 35

def raw_vector_with(word_list)
  clear_cache!
  super
end

#transposed_search_vectorObject

Cache the transposed vector, it gets used a lot



30
31
32
# File 'lib/classifier-reborn/lsi/cached_content_node.rb', line 30

def transposed_search_vector
  @transposed_search_vector ||= super
end