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

How to set OpenNLP Model binary file path in Eclipse?

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

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

这是我正在尝试的代码 运行 但它给出了以下错误

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)

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

如您所见,它正在显示

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

您还没有添加必要的依赖项 libraries.In 您提供的 link 有一个名为 de-sent.bin.You 的 bin 必须将其添加到库路径

我找到了解决方案。

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