stanford的StaggerDemo的corenlp包
我想让一个程序自动标记目录中的文本。这是我的第一步。 我对 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.* 无法导入...
非常感谢。
I wanna make a program automatically tagger the text in a directory. Here's my first step.
I made a little change to TaggerDemo.java. But it is not working properly as expected.
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));
}
}
}
This is the error i got.
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)
Why it says file not found?
When i tried to compile it under terminal, it says edu.stanford.nlp.ling.* can not be imported...
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当前目录中似乎没有
sample-input.txt
文件。要查看当前目录,请使用:
It seems that you don't have the file
sample-input.txt
in the current directory.To see your current directory, use: