2015-09-15 27 views
0

我已经从opennlp下载了Apache opennlp,解压后在引用的库中添加了两个.jar文件。写一个简单的代码:如何在Eclipse Luna的Java项目中使用Apache OpenNLP?

modelIn = new FileInputStream("en-sent.bin"); 

OUTPUT:

java.io.FileNotFoundException: en-sent.bin (The system cannot find the file specified) 
at java.io.FileInputStream.open0(Native Method) 
at java.io.FileInputStream.open(Unknown Source) 
at java.io.FileInputStream.<init>(Unknown Source) 
at java.io.FileInputStream.<init>(Unknown Source) 
at Home.main(Home.java:16) 
+1

请重新格式化,使之明确。把你的栈跟踪也放在代码块中。有一堆///不会帮助任何人。 – Adarsha

+0

[为什么加载POSModel文件不能在WEB-INF文件夹中工作?](http://stackoverflow.com/questions/32148328/why-does-the-loading-of-a-postodel -file-not-work-from-the-web-inf-folder) – MWiesner

回答

0

我会建议使用Maven对于那些依赖关系。

为了将句子检测API集成到Java项目中,您需要从http://opennlp.sourceforge.net/models-1.5/下载预先训练过的模型en-sent.bin,并将其添加到您的类路径中或指向文件系统上的完整路径。

后按照阿帕奇OpenNLP文档:

InputStream modelIn = new FileInputStream("en-sent.bin"); 

try { 
    SentenceModel model = new SentenceModel(modelIn); 
} 
catch (IOException e) { 
    e.printStackTrace(); 
} 
finally { 
    if (modelIn != null) { 
    try { 
     modelIn.close(); 
    } 
    catch (IOException e) { 
    } 
    } 
} 

我真的要推荐这里阅读更多关于它:http://blog.dpdearing.com/2011/05/opennlp-1-5-0-basics-sentence-detection-and-tokenizing/这里:http://www.javaworld.com/article/2077352/java-se/smartly-load-your-properties.html

+0

Thanx @Shmulik Klein问题现已解决.. –

+0

欢迎您接受答案并评分;) –

相关问题