Sha256: 440374dbf485254a72a3566604a7542d4c5803ec10ae060831c2b4a6826780a4

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

# Author::    Kelley Reynolds  (mailto:kelley@insidesystems.net)
# Copyright:: Copyright (c) 2015 Kelley Reynolds
# License::   LGPL

module ClassifierReborn

  # 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
  class CachedContentNode < ContentNode
    module InstanceMethods
      # Go through each item in this index and clear the cache
      def clear_cache!
        @items.each_value(&:clear_cache!)
      end
    end

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

    def clear_cache!
      @transposed_search_vector = nil
    end

    # Cache the transposed vector, it gets used a lot
    def transposed_search_vector
      @transposed_search_vector ||= super
    end
    
    # Clear the cache before we continue on
    def raw_vector_with( word_list )
      clear_cache!
      super
    end
    
    # We don't want the cached_data here
    def marshal_dump
      [@lsi_vector, @lsi_norm, @raw_vector, @raw_norm, @categories, @word_hash]
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
classifier-reborn-2.0.4 lib/classifier-reborn/lsi/cached_content_node.rb