如何在Eclipse中设置OpenNLP Model二进制文件路径?

时间:2015-06-21 18:33:03

标签: java eclipse nlp opennlp

我已经从here下载了二进制模型文件,但我没有得到如何设置路径。我正在使用Eclipse,我尝试将这些二进制文件添加到我的项目路径中。第二点是,我没有在Maven项目上工作。

template

这是我尝试运行的代码,但它会出现以下错误

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();
    }
}
}

这是我刚开始的项目的层次结构 ScreenShot

2 个答案:

答案 0 :(得分:2)

我得到了解决方案。

This helped me to crack the problem 基本上我所做的是我给出了文件的绝对路径而不是相对路径。

答案 1 :(得分:1)

正如您所看到的那样

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

您还没有添加必要的依赖库。在您提供的链接中,有一个名为de-sent.bin的bin。您必须将其添加到库路径

enter image description here