Class: OpenNLP::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/open-nlp/base.rb

Instance Method Summary collapse

Constructor Details

#initialize(file_or_arg = nil, *args) ⇒ Base

Returns a new instance of Base.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/open-nlp/base.rb', line 3

def initialize(file_or_arg=nil, *args)

  @proxy_class = OpenNLP::Bindings.const_get(last_name)

  if requires_model?
    if !file_or_arg && !has_default_model?
      raise "No default model files are available for " +
      "class #{last_name}. Please supply a model as" +
      "an argument to the constructor."
    end
    @model = OpenNLP::Bindings.get_model(last_name, file_or_arg)
    @proxy_inst = @proxy_class.new(*([@model] + args))
  else
    @proxy_inst = @proxy_class.new(*([*file_or_arg] + args))
  end

end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



35
36
37
# File 'lib/open-nlp/base.rb', line 35

def method_missing(sym, *args, &block)
  @proxy_inst.send(sym, *args, &block)
end

Instance Method Details

#has_default_model?Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/open-nlp/base.rb', line 21

def has_default_model?
  name = OpenNLP::Config::ClassToName[last_name]
  !OpenNLP::Config::DefaultModels[name].empty?
end

#last_nameObject



30
31
32
# File 'lib/open-nlp/base.rb', line 30

def last_name
  self.class.to_s.split('::')[-1]
end

#requires_model?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/open-nlp/base.rb', line 26

def requires_model?
  OpenNLP::Config::RequiresModel.include?(last_name)
end