2011-05-16 123 views
-2

我想讓一個程序自動標記目錄中的文本。這是我的第一步。 我對TaggerDemo.java做了一些改動。但它沒有像預期的那樣正常工作。斯坦福的stangerDemo的corenlp包

import java.io.BufferedReader; 
import java.io.FileReader; 
import java.util.ArrayList; 
import java.util.List; 

import edu.stanford.nlp.ling.HasWord; 
import edu.stanford.nlp.ling.Sentence; 
import edu.stanford.nlp.ling.TaggedWord; 
import edu.stanford.nlp.tagger.maxent.MaxentTagger; 

class auto{ 

    public static void main (String[] args) throws Exception{ 

    MaxentTagger tagger = new MaxentTagger("models/left3words-wsj-0-18.tagger"); 
    @SuppressWarnings("unchecked") 
    List<List<HasWord>> sentences = tagger.tokenizeText(new BufferedReader(new FileReader(args[0]))); 
    for (List<HasWord> sentence : sentences) { 
     ArrayList<TaggedWord> tSentence = tagger.tagSentence(sentence); 
     System.out.println(Sentence.listToString(tSentence, false)); 
    } 
    } 

} 

這是我得到的錯誤。

Loading default properties from trained tagger models/left3words-wsj-0-18.tagger 
Reading POS tagger model from models/left3words-wsj-0-18.tagger ... done [2.9 sec]. 
Exception in thread "main" java.io.FileNotFoundException: sample-input.txt (No such file or directory) 
    at java.io.FileInputStream.open(Native Method) 
    at java.io.FileInputStream.<init>(FileInputStream.java:106) 
    at java.io.FileInputStream.<init>(FileInputStream.java:66) 
    at java.io.FileReader.<init>(FileReader.java:41) 
    at auto.main(auto.java:17) 

爲什麼說找不到文件?

,當我試圖編譯它在終端,它說edu.stanford.nlp.ling *不能導入...

非常感謝。

+0

你是如何運行的程序?似乎'sample-input.txt'只是在不同的目錄中。 – 2011-05-16 11:56:23

回答

1

看來你沒有在當前目錄中的文件sample-input.txt

要查看當前目錄,使用:

File f = new File("."); 
System.out.println(f.getAbsolutePath()); 
+0

非常感謝......我剛剛發現,在ubuntu中使用eclipse時,應該添加/ src,而在Windows中,直接使用文件名即可。 – elfandi 2011-05-18 04:47:26