stanford的StaggerDemo的corenlp包

发布于 2024-11-07 08:02:02 字数 1573 浏览 5 评论 0原文

我想让一个程序自动标记目录中的文本。这是我的第一步。 我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇妻 2024-11-14 08:02:02

当前目录中似乎没有 sample-input.txt 文件。

要查看当前目录,请使用:

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

It seems that you don't have the file sample-input.txt in the current directory.

To see your current directory, use:

File f = new File(".");
System.out.println(f.getAbsolutePath());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文