Sha256: d7ad0b4fde5fcc139783953a4fb08332d05685d4270679833db14b13817c4a30

Contents?: true

Size: 1.1 KB

Versions: 6

Compression:

Stored size: 1.1 KB

Contents

class OpenNLP::Base

  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

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

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

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


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

  def get_list(tokens)
    list = OpenNLP::Bindings::ArrayList.new
    tokens.each do |t|
      list.add(OpenNLP::Bindings::String.new(t.to_s))
    end
    list
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
open-nlp-0.1.5 lib/open-nlp/base.rb
open-nlp-0.1.4 lib/open-nlp/base.rb
open-nlp-0.1.3 lib/open-nlp/base.rb
open-nlp-0.1.2 lib/open-nlp/base.rb
open-nlp-0.1.1 lib/open-nlp/base.rb
open-nlp-0.1.0 lib/open-nlp/base.rb