我已經下載從here二進制模型文件,但我沒有得到我該如何要設置的路徑。我正在使用Eclipse,我試圖將這些二進制文件添加到我的項目的路徑中。第二點是,我不在Maven項目上工作。如何在Eclipse中設置OpenNLP模型二進制文件路徑?
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)
這是我剛開始
你可以看到有關於project.Just紅色指示燈看到它是在錯誤控制檯 – Madhan
說什麼錯誤我解決了錯誤,它說,歸檔或ZIP之一是腐敗。我從文件夾中刪除了該ZIP文件,現在沒有紅色驚歎號,但仍然有相同的輸出。 –
[幫我,謝謝你,我早該想到的其他方式來搜索] [1] [1]:http://stackoverflow.com/questions/22978170/java-io-filenotfoundexception-in -eclipse –