在 NLP 项目中获取 FileNotFoundException
Getting the FileNotFoundException in the NLP project
我作为初学者开始从事 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 -> Modules -> Dependencies -> Selected Project SDK 添加了文件,并使用 (+) 符号添加了文件 JAR or Directories
。如下图。
如何在项目中解决这个FileNotFoundException
?
项目更新图:
将 en-sent.bin 与 src 文件夹平行放置,它应该可以工作。
或者,提供绝对路径 - 而不是相对路径。
我作为初学者开始从事 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 -> Modules -> Dependencies -> Selected Project SDK 添加了文件,并使用 (+) 符号添加了文件 JAR or Directories
。如下图。
如何在项目中解决这个FileNotFoundException
?
项目更新图:
将 en-sent.bin 与 src 文件夹平行放置,它应该可以工作。
或者,提供绝对路径 - 而不是相对路径。