tags:

views:

32

answers:

1

Hello, I am trying to implement a collection of java classes from the Stanford NLP Parser in jRuby

I am able to implement regular Java in jRuby, but not the Stanford Parser classes

#my requires/imports/includes, included multiple versions to be safe
require 'java'
include Java
require 'c:\\stanford-parser\\stanfordparser.jar'
require 'C:\\Stanford-Parser\\Current\\stanford-parser.jar'
require 'c:\\sun\\stanfordparser'
require 'rubygems'
include_class 'edu.stanford.nlp.parser.lexparser.LexicalizedParser'


#try to create an object of the java class i am importing, LexicalizedParser
lp = edu.stanford.nlp.parser.lexparser.LexicalizedParser
#the line above is what causes the error

#check if regular Java is working
list = java.util.ArrayList.new 
a = "1"
b = "2"
list.add(a)
list.add(b)
d = list[0]
puts d # all of this works

I get this error

~\rubyjavatest\lib\main.rb:15: undefined local variable or method `edu' for main:Object (NameError)

(the ~ represents I cut out the whole path to shorten this)

also if I try this:

lp = java::edu::stanford::nlp.parser::lexparser::LexicalizedParser

I get this error

~\rubyjavatest\lib\main.rb:15: cannot load Java class java.edu.stanford.nlp.parser.lexparser.LexicalizedParser (NameError)

Any help would be great!

+2  A: 

Try this: lp = LexicalizedParser.new

You need to call new like you did with ArrrayList. Also, you shouldn't need to list the fully qualified class name after you call include_class.

I am not familiar with the Stanford NLP Parser, so I am assuming this will work. It might be necessary to pass additional parameters to the constructor.

dbyrne
That worked! Thanks so much.
Andrew