The ruby code we were trying to execute based on https://github.com/louismullie/open-nlp/blob/master/README.md:
#gem inclusion
require 'open-nlp'
# Set an alternative path to look for the JAR files.
# Default is gem's bin folder.
OpenNLP.jar_path = '/home/USER/.rvm/gems/ruby-2.1.2/gems/open-nlp-0.1.5/bin/'
# Set an alternative path to look for the model files.
# Default is gem's bin folder.
OpenNLP.model_path = '/home/USER/.rvm/gems/ruby-2.1.2/gems/open-nlp-0.1.5/bin/'
# Pass some alternative arguments to the Java VM.
# Default is ['-Xms512M', '-Xmx1024M'].
OpenNLP.jvm_args = ['-Xms512M', '-Xmx1024M']
# Redirect VM output to log.txt
OpenNLP.log_file = 'log.txt'
# Set default models for a language.
OpenNLP.use :language
#Maximum entropy tokenizer, chunker and POS tagger
OpenNLP.load
chunker = OpenNLP::ChunkerME.new
tokenizer = OpenNLP::TokenizerME.new
tagger = OpenNLP::POSTaggerME.new
sent = "The death of the poet was kept from his poems."
tokens = tokenizer.tokenize(sent).to_a
# => %w[The death of the poet was kept from his poems .]
tags = tagger.tag(tokens).to_a
# => %w[DT NN IN DT NN VBD VBN IN PRP$ NNS .]
chunks = chunker.chunk(tokens, tags).to_a
# => %w[B-NP I-NP B-PP B-NP I-NP B-VP I-VP B-PP B-NP I-NP O]
And that is the output:
/home/USER/.rvm/gems/ruby-2.1.2/gems/open-nlp-0.1.5/lib/open-nlp/bindings.rb:125:in `+': no implicit conversion of nil into String (TypeError)
from /home/USER/.rvm/gems/ruby-2.1.2/gems/open-nlp-0.1.5/lib/open-nlp/bindings.rb:125:in `load_model'
from /home/USER/.rvm/gems/ruby-2.1.2/gems/open-nlp-0.1.5/lib/open-nlp/bindings.rb:110:in `get_model'
from /home/USER/.rvm/gems/ruby-2.1.2/gems/open-nlp-0.1.5/lib/open-nlp/base.rb:13:in `initialize'
from opennlp_example.rb:26:in `new'
from opennlp_example.rb:26:in `<main>'
As it is just the example (Simple tokenizer example is running fine)... we hope someone knows more about that
Looking at the code it seems that OpenNLP::Config::DefaultModels[name][OpenNLP.language]
is nil
:
def self.load_model(name, file = nil) if self.models[name] && file == self.model_files[name] return self.models[name] end models = OpenNLP::Config::DefaultModels[name] file ||= models[self.language] # <- this is the problematic line path = self.model_path + file stream = FileInputStream.new(path)
I suspect that checking OpenNLP.language
would yield :language
, from the line:
# Set default models for a language.
OpenNLP.use :language
As the implementation for use
is:
def self.use(language) self.language = language end
Bottom line - try removing OpenNLP.use :language
from your code, or changing it to OpenNLP.use :english