Class: CorrectHorseBatteryStaple::Corpus

Inherits:
Object
  • Object
show all
Defined in:
lib/correct_horse_battery_staple/corpus.rb

Direct Known Subclasses

Base

Defined Under Namespace

Classes: Base, Isam, IsamKD, Redis, Redis2, Serialized, Sqlite

Class Method Summary collapse

Class Method Details

.format_for(spec, defval = nil) ⇒ Object



18
19
20
21
22
# File 'lib/correct_horse_battery_staple/corpus.rb', line 18

def self.format_for(spec, defval = nil)
  File.extname(spec)[1..-1].downcase || defval
rescue
  defval
end

.read(filename, clazz = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/correct_horse_battery_staple/corpus.rb', line 3

def self.read(filename, clazz=nil)
  clazz ||=
    case CorrectHorseBatteryStaple::Corpus.format_for(filename)
    # when 'kdtree' then CorrectHorseBatteryStaple::Corpus::KDTree
    when 'isam' then CorrectHorseBatteryStaple::Corpus::Isam
    when 'kdtree', 'isamkd' then CorrectHorseBatteryStaple::Corpus::IsamKD
    when 'sqlite' then CorrectHorseBatteryStaple::Corpus::Sqlite
    when 'redis2' then CorrectHorseBatteryStaple::Corpus::Redis2
    when 'redis' then CorrectHorseBatteryStaple::Corpus::Redis
    else CorrectHorseBatteryStaple::Corpus::Serialized
    end

  clazz.read(filename)
end