Class: OpenNLP::Base
- Inherits:
-
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
#last_name ⇒ Object
30
31
32
|
# File 'lib/open-nlp/base.rb', line 30
def last_name
self.class.to_s.split('::')[-1]
end
|
#requires_model? ⇒ Boolean