2

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

CocoCrisp
  • 807
  • 1
  • 9
  • 26
  • as you can see there is red indicator on the project.Just see what error it is saying in the error console – Madhan Jun 21 '15 at 18:36
  • I resolved that error, it said that one of the archive or ZIP was corrupt. I removed that ZIP from the folder,now no red Exclamation is there but still the same output i am getting. – CocoCrisp Jun 21 '15 at 18:43
  • [This Helped me, Thanks, i should have thought the other way to search][1] [1]: http://stackoverflow.com/questions/22978170/java-io-filenotfoundexception-in-eclipse – CocoCrisp Jun 21 '15 at 19:27
  • You can always answer your question.There will be a Answer your question button at the bottom – Madhan Jun 21 '15 at 19:36
  • OK there it is ,the answer. Thanks Madhan. – CocoCrisp Jun 21 '15 at 19:45

2 Answers2

2

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.

Community
  • 1
  • 1
CocoCrisp
  • 807
  • 1
  • 9
  • 26
1

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

Madhan
  • 5,750
  • 4
  • 28
  • 61
  • But i want to use "en-sent.bin" ie model file for english language, and therefore i have added this bin file only. You can check there is a column named "Language" on the lest most side. – CocoCrisp Jun 21 '15 at 19:12
  • I have tried it before, it gives the same Exception.Actually i think i have not given the proper path, if you can help me out with that that would be great, i have already added OPENNPL_HOME and given the path of the directory in which i have kept all the bin files. Its still not Working. – CocoCrisp Jun 21 '15 at 19:16
  • after setting the path have you relaunched the eclipse.If not relaunch the eclipse coz it might be referring the old values – Madhan Jun 21 '15 at 19:19
  • Actually Sorry I have posted the question incorrectly. When i try to use de-sent.bin it gives the same error as when i use en-sent.bin – CocoCrisp Jun 21 '15 at 19:19
  • No, the same Exception ! – CocoCrisp Jun 21 '15 at 19:23