How to set OpenNLP Model binary file path in Eclipse?

2k views Asked by At

I have downloaded the Binary model files from here but i am not getting how do i have to set the path. I am using Eclipse, i tried adding these binary file into the path of my project.Second point is,I am not working on Maven Project.

import opennlp.tools.sentdetect.SentenceDetectorME;
import opennlp.tools.sentdetect.SentenceModel;
import opennlp.tools.util.InvalidFormatException;

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


public class OpenNlpTest {

public static void SentenceDetect() throws InvalidFormatException,
IOException {
String paragraph = "Hi. How are you? This is Mike.";

// always start with a model, a model is learned from training data
InputStream is = new FileInputStream("en-sent.bin");
SentenceModel model = new SentenceModel(is);
SentenceDetectorME sdetector = new SentenceDetectorME(model);

String sentences[] = sdetector.sentDetect(paragraph);

System.out.println(sentences[0]);
System.out.println(sentences[1]);
is.close();

}
public static void main(String []z){

    try {
        SentenceDetect();
    } catch (InvalidFormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
}

this is the code i am trying to run but it gives the following error

java.io.FileNotFoundException: en-sent.bin (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at OpenNlpTest.SentenceDetect(OpenNlpTest.java:17)
at OpenNlpTest.main(OpenNlpTest.java:31)

This is the hierarchy of my project which i have just started ScreenShot

2

There are 2 answers

1
CocoCrisp On BEST ANSWER

I got the solution.

This helped me to crack the problem Basically what I did is I gave the absolute path of the file rather than relative path.

5
Madhan On

As you can see it is showing

java.io.FileNotFoundException: de-sent.bin (The system cannot find the file specified)

You haven't added necessary dependent libraries.In the link you've provided there is a bin named de-sent.bin.You have to add it to the library path

enter image description here