2

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!

1
  • i am assuming you got this to work. i am getting a Loading parser from serialized file /u/nlp/data/lexparser/englishPCFG.ser.gz ... File not found: /u/nlp/data/lexparser/englishPCFG.ser.gz Commented Nov 6, 2011 at 8:14

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.