Why the HelloWorld of opennlp library works fine on Java but doesn't work with Jruby?

Posted by 0x90 on Stack Overflow See other posts from Stack Overflow or by 0x90
Published on 2012-10-20T21:47:59Z Indexed on 2012/10/20 23:01 UTC
Read the original article Hit count: 228

Filed under:
|
|
|

I am getting this error:

SyntaxError: hello.rb:13: syntax error, unexpected tIDENTIFIER
public HelloWorld( InputStream data ) throws IOException {

The HelloWorld.rb is:

require "java"

import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;

import opennlp.tools.postag.POSModel;
import opennlp.tools.postag.POSTaggerME;

public class HelloWorld {
    private POSModel model;

    public HelloWorld( InputStream data ) throws IOException {
    setModel( new POSModel( data ) );
    }

    public void run( String sentence ) {
    POSTaggerME tagger = new POSTaggerME( getModel() );
    String[] words = sentence.split( "\\s+" );
    String[] tags = tagger.tag( words );
    double[] probs = tagger.probs();

    for( int i = 0; i < tags.length; i++ ) {
    System.out.println( words[i] + " => " + tags[i] + " @ " + probs[i] );
    }
    }

    private void setModel( POSModel model ) {
    this.model = model;
    }

    private POSModel getModel() {
    return this.model;
    }

    public static void main( String args[] ) throws IOException {
    if( args.length < 2 ) {
    System.out.println( "HelloWord <file> \"sentence to tag\"" );
    return;
    }

    InputStream is = new FileInputStream( args[0] );
    HelloWorld hw = new HelloWorld( is );
    is.close();

    hw.run( args[1] );
    }
}

when running ruby HelloWorld.rb "I am trying to make it work"

when I run the HelloWorld.java "I am trying to make it work" it works perfectly, of course the .java doesn't contain the require java statement.

EDIT:

I followed the following steps.

The output for jruby -v :

jruby 1.6.7.2 (ruby-1.8.7-p357) (2012-05-01 26e08ba) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_35) [darwin-x86_64-java]

© Stack Overflow or respective owner

Related posts about java

Related posts about osx