class Cassiopee::CrawlerCache

Class maning cache of results

Constants

FILE_CACHE_EXT

Attributes

cache[RW]
errors[RW]

max errors

file_suffix[RW]

Suffix files name/path

max_position[RW]
method[RW]

search exact: 0 hamming : 1 edit : 2

min_position[RW]

filter

Public Class Methods

new() click to toggle source
# File lib/cassiopee.rb, line 175
        def initialize
                @file_suffix = "crawler"
end

Public Instance Methods

clearCache() click to toggle source
# File lib/cassiopee.rb, line 206
def clearCache
        File.delete(@file_suffix+FILE_CACHE_EXT) unless !File.exists?(@file_suffix+FILE_CACHE_EXT)
end
loadCache() click to toggle source

Loads cache from file

# File lib/cassiopee.rb, line 180
def loadCache
return Array.new unless File.exists?(@file_suffix+FILE_CACHE_EXT)
begin
  file = Zlib::GzipReader.open(@file_suffix+FILE_CACHE_EXT)
rescue Zlib::GzipFile::Error
  file = File.open(@file_suffix+FILE_CACHE_EXT, 'r')
ensure
    obj =  Marshal.load file.read
    file.close
                        if(method!=obj.method || min_position<obj.min_position || max_position>obj.max_position || errors>obj.errors)
                                return Array.new
                        end
    return filterCache(obj)
end                     
end
saveCache(obj) click to toggle source

Save self to cache, with cache object set from obj

# File lib/cassiopee.rb, line 197
def saveCache(obj)
        self.cache = obj
        marshal_dump = Marshal.dump(self)
        sfxpos = File.new(@file_suffix+FILE_CACHE_EXT,'w')
        sfxpos = Zlib::GzipWriter.new(sfxpos)
        sfxpos.write marshal_dump
        sfxpos.close
end
setLogger(userlogger) click to toggle source
# File lib/cassiopee.rb, line 171
def setLogger(userlogger)
        $log = userlogger
end

Private Instance Methods

filterCache(cacheobject) click to toggle source

filter cache according to settings obj: cache object

# File lib/cassiopee.rb, line 214
def filterCache(cacheobject)
        
        realmatches = Array.new
        if(cacheobject==nil)
                return realmatches
        end
        
        cacheobject.cache.each do |obj|
                if(obj[1]>self.errors)
                        next
                end
                realpos = Array.new
                realpos << obj[2][0]
                (1..obj[2].length-1).each do |i|
                    curpos= obj[2][i]
                        if((curpos<=max_position || max_position==0) && curpos>=min_position)
                                realpos << curpos
                        end
                end
                if(realpos.length<=1)
                        next
                end
                realmatches << Array[obj[0],obj[1],realpos]
                
        end
        return realmatches
end