2015-06-21 225 views
1

我已經下載從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) 

這是我剛開始 ScreenShot

+0

你可以看到有關於project.Just紅色指示燈看到它是在錯誤控制檯 – Madhan

+0

說什麼錯誤我解決了錯誤,它說,歸檔或ZIP之一是腐敗。我從文件夾中刪除了該ZIP文件,現在沒有紅色驚歎號,但仍然有相同的輸出。 –

+0

[幫我,謝謝你,我早該想到的其他方式來搜索] [1] [1]:http://stackoverflow.com/questions/22978170/java-io-filenotfoundexception-in -eclipse –

回答

2

我在斌解。

This helped me to crack the problem 基本上我所做的是給了文件的絕對路徑而不是相對路徑。

+0

好吧,這不是一個好的解決方案,因爲它不會在其他環境中擴展。 – MWiesner

1

正如你可以在我的項目的層次結構看到它正在顯示

java.io.FileNotFoundException: de-sent.bin (The system cannot find the file specified)

您沒有必要添加依賴libraries.In您所提供的鏈接中有一個名爲de-sent.bin.You已經將其添加到資料庫路徑

enter image description here

+0

但我想使用「en-sent.bin」即英文語言的模型文件,因此我只添加了這個bin文件。最重要的是您可以檢查是否有名爲「語言」的列。 –

+0

只是把它添加到庫中,並嘗試運行,看看有什麼輸出.. – Madhan

+0

我曾經使用過,它給出了同樣的Exception.Actually我想我已經沒有給予正確的路徑,如果你能幫助我與那會很好,我已經添加了OPENNPL_HOME並給出了我保存所有bin文件的目錄的路徑。它仍然不工作。 –

相關問題