views:

42

answers:

2

Hello, 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 windows 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.

A: 

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.

John Topley
thanksI added 'stanfordparser' to config/environment.rb and I got the following error org.jruby.exceptions.MainExitException: aborted java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:222) java.util.concurrent.FutureTask.get(FutureTask.java:83) com.sun.grizzly.jruby.RackGrizzlyAdapter.service(RackGrizzlyAdapter.java:289)etc etc (it kept going for a while)I looked at the glassfish server logs and it says SEVERE: Missing these required gems: stanfordparser ive run rake gems:install, and netbeans says that it is installed, so I don't know what the problem is
Andrew
A: 

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
Andrew