2015-09-15 57 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

歡迎您接受答案並評分;) –

相關問題