我想让一个程序自动标记目录中的文本。这是我的第一步。我对 TaggerDemo.java 做了一点改动。但它没有按预期正常工作。
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.* 无法导入...
非常感谢。