Class: Treat::Loaders::BindIt

Inherits:
Object
  • Object
show all
Defined in:
lib/treat/loaders/bind_it.rb

Direct Known Subclasses

OpenNLP, Stanford

Constant Summary collapse

@@loaded =

Keep track of whether its loaded or not.

{}

Class Method Summary collapse

Class Method Details

.load(klass, name, language = nil) ⇒ Object

Load CoreNLP package for a given language.


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/treat/loaders/bind_it.rb', line 7

def self.load(klass, name, language = nil)
  
  return if @@loaded[klass]
  
  language ||= Treat.core.language.default

  jar_path   = Treat.libraries[name].jar_path || 
               Treat.paths.bin + "#{name}/"
  model_path = Treat.libraries[name].model_path || 
               Treat.paths.models + "#{name}/"
             
  if !File.directory?(jar_path)
    raise Treat::Exception, "Looking for #{klass} " +
    "library JAR files in #{jar_path}, but it is " +
    "not a directory. Please set the config option " +
    "Treat.libraries.#{name}.jar_path to a folder " +
    "containing the appropriate JAR files."
  end
  
  if !File.directory?(model_path)
    raise Treat::Exception, "Looking for #{klass} " +
    "library model files in #{model_path}, but it " +
    "is not a directory. Please set the config option " +
    "Treat.libraries.#{name}.model_path to a folder " +
    "containing the appropriate JAR files."
  end
  
  klass.jar_path = jar_path
  klass.model_path = model_path
  klass.use language
  
  if Treat.core.verbosity.silence
    if Gem.win_platform?
      klass.log_file = 'NUL'
    else
      klass.log_file = '/dev/null'
    end
  end

  klass.bind
  
  @@loaded[klass] = true
  
end