【问题标题】:Error in creating the StanfordCoreNLP object创建 StanfordCoreNLP 对象时出错
【发布时间】:2014-03-05 18:25:46
【问题描述】:

我已经从http://nlp.stanford.edu/software/corenlp.shtml#Download下载并安装了所需的jar文件。

我已经包含了五个 jar 文件

Satnford-postagger.jar

斯坦福-psotagger-3.3.1.jar

斯坦福-psotagger-3.3.1.jar-javadoc.jar

斯坦福-psotagger-3.3.1.jar-src.jar

stanford-corenlp-3.3.1.jar

代码是

public class lemmafirst {

    protected StanfordCoreNLP pipeline;

    public lemmafirst() {
        // Create StanfordCoreNLP object properties, with POS tagging
        // (required for lemmatization), and lemmatization
        Properties props;
        props = new Properties();
        props.put("annotators", "tokenize, ssplit, pos, lemma");

        /*
         * This is a pipeline that takes in a string and returns various analyzed linguistic forms. 
         * The String is tokenized via a tokenizer (such as PTBTokenizerAnnotator), 
         * and then other sequence model style annotation can be used to add things like lemmas, 
         * POS tags, and named entities. These are returned as a list of CoreLabels. 
         * Other analysis components build and store parse trees, dependency graphs, etc. 
         * 
         * This class is designed to apply multiple Annotators to an Annotation. 
         * The idea is that you first build up the pipeline by adding Annotators, 
         * and then you take the objects you wish to annotate and pass them in and 
         * get in return a fully annotated object.
         * 
         *  StanfordCoreNLP loads a lot of models, so you probably
         *  only want to do this once per execution
         */
        ***this.pipeline = new StanfordCoreNLP(props);***
}

我的问题在于创建管道。

我得到的错误是:

Exception in thread "main" java.lang.RuntimeException: edu.stanford.nlp.io.RuntimeIOException: Unrecoverable error while loading a tagger model
    at edu.stanford.nlp.pipeline.StanfordCoreNLP$4.create(StanfordCoreNLP.java:563)
    at edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:81)
    at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:262)
    at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:129)
    at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:125)
    at lemmafirst.<init>(lemmafirst.java:39)
    at lemmafirst.main(lemmafirst.java:83)
Caused by: edu.stanford.nlp.io.RuntimeIOException: Unrecoverable error while loading a tagger model
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:758)
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:289)
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:253)
    at edu.stanford.nlp.pipeline.POSTaggerAnnotator.loadModel(POSTaggerAnnotator.java:88)
    at edu.stanford.nlp.pipeline.POSTaggerAnnotator.<init>(POSTaggerAnnotator.java:76)
    at edu.stanford.nlp.pipeline.StanfordCoreNLP$4.create(StanfordCoreNLP.java:561)
    ... 6 more
Caused by: java.io.IOException: Unable to resolve "edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger" as either class path, filename or URL
    at edu.stanford.nlp.io.IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(IOUtils.java:434)
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:753)
    ... 11 more

谁能更正错误?谢谢

【问题讨论】:

    标签: java maven jar nlp stanford-nlp


    【解决方案1】:

    抛出的异常是由于缺少 pos 模型。这是因为有和没有模型文件的可下载版本。

    要么添加 stanford-postagger-完整-3.3.1.jar 可以在以下页面上找到 (stanford-postagger-full-2014-01-04.zip): http://nlp.stanford.edu/software/tagger.shtml .

    或者您对整个 CoreNLP 包(stanford-corenlp-full....jar)执行相同的操作: http://nlp.stanford.edu/software/corenlp.shtml (然后你也可以删除所有 postagger 依赖,它们包含在 CoreNLP 中)

    如果您只想添加模型文件,请查看Maven Central 并下载“stanford-corenlp-3.3.1-models.jar”。

    【讨论】:

    • 简答:从这里下载完整的 CoreNLP 包,其中包括模型文件:nlp.stanford.edu/software/corenlp.shtml
    • 非常感谢。我添加了 stanford-corenlp-3.3.1-models.jar 它对我有用。谢谢 Chirtopher..
    • 我试过这个但由于某种原因没有工作。然后我使用 jarsplice 将我的 jar 和 ..-models.jar 拼接起来,它起作用了。
    【解决方案2】:

    添加这些模型文件的更简单方法是在 pom.xml 中添加以下依赖项,然后让 maven 为您管理它:

    <dependency>
      <groupId>edu.stanford.nlp</groupId>
      <artifactId>stanford-corenlp</artifactId>
      <version>3.6.0</version>
    </dependency>
    <dependency>
      <groupId>edu.stanford.nlp</groupId>
      <artifactId>stanford-corenlp</artifactId>
      <version>3.6.0</version>
      <classifier>models</classifier> <!--  will get the dependent model jars -->
    </dependency>
    

    【讨论】:

    • 感谢@Sruthi Poddutur 的评论。它有助于解决我的问题。
    • 对于gradle,build.gradle应该写什么?
    【解决方案3】:

    如果有人在寻找 gradle 依赖项,请在依赖项下添加以下内容。

     compile group: 'edu.stanford.nlp', name: 'stanford-corenlp', version: '3.9.1'
     compile group: 'edu.stanford.nlp', name: 'stanford-corenlp', version: '3.9.1', classifier: 'models'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-20
      • 2020-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多