我作为初学者开始研究NLP项目,并添加了en-sent.bin
文件来运行下面提供的方法,
public static void SentenceDetect() {
try {
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();
} catch (InvalidFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
我在Intellij
,
java.io.FileNotFoundException: en-sent.bin (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at com.nlp.processor.MyNlp.SentenceDetect(MyNlp.java:22)
at com.nlp.processor.MyNlp.main(MyNlp.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
问题是我将en-sent.bin
放在项目中,如下图所示。
我添加了来自Intellij的文件 - &gt;模块 - &gt;依赖关系 - &gt;在Project SDK上选择并使用(+)符号作为JAR or Directories
添加文件。如下图。
如何解决项目中的FileNotFoundException
?
项目的更新图:
答案 0 :(得分:0)
将en-sent.bin与src文件夹并行,它应该可以工作。
或者,提供绝对路径 - 而不是相对路径。