开发者

uninitialized constant on class from ruby gem

I am trying to implement a gem called stanfordparser which can be found here: http://stanfordparser.rubyforge.org/

It is a ruby wrapper for a java natural language parser

I am developing in netbeans using ruby on rails / jruby on a wi开发者_JS百科ndows 7 machine. My web app works fine otherwise, but when I try to add the parser wrapper it breaks.

Here is the code that is causing a problem:

gem 'stanfordparser'

def show
 parser = StanfordParser::LexicalizedParser.new
 @words = parser.apply("This is a sentence.")
end

this is in the taskscontroller

and when I go to tasks/show (which, if i remove this code, works fine) I get the following error

uninitialized constant TasksController::StanfordParser

I have made sure the gem is installed in netbeans

I am very new to ruby on rails, and teaching myself, so it may be something obvious

Thanks!

EDIT: I checked my glassfish server logs and it says

SEVERE: Missing these required gems:
  stanfordparser

which is weird because I've installed the gem using netbeans, I've done rake gems:install and netbeans says the gem is installed. I've checked in netbeans gems folder and the gem is installed there.

EDIT 2:

So, after a lot of research and head banging, I've decided to simplify things a bit by just trying to use jruby to implement the java classes, now I need to figure out how to import the stanfordparser java classes (there are at least 50), I think I need to compress all the classes into a jar so that jruby can load it. maybe.


If you are using Rails 3 then the gem 'stanfordparser' statement needs to be specified in Bundler's Gemfile within the project's root. Otherwise, for Rails 2.x you need a config.gem 'stanfordparser' statement within config/environment.rb.


I was able to solve my problem the following way:

instead of using the stanfordparser ruby wrapper (which implements java ruby bridge to connect the java stanford parser to pure ruby), I use jruby to just implement the java from the stanford parser.

the code that ended up working:

include Java
require 'C:\\Stanford-Parser\\Current\\stanford-parser.jar'
require 'rubygems'
include_class 'edu.stanford.nlp.parser.lexparser.LexicalizedParser'

lp = LexicalizedParser.new(args) #args is the arguments, not copied here
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜