繁体   English   中英

Stanford CoreNLP-单词的合法化

[英]Stanford CoreNLP - Leematisation of Words

我正在尝试使用Stanford NLP简化句子,使用以下代码

import java.util.*;
import edu.stanford.nlp.pipeline.*;
import edu.stanford.nlp.ling.*;
import edu.stanford.nlp.ling.CoreAnnotations.*;
import edu.stanford.nlp.util.CoreMap;

public class Entry
{
    public static void main(String[] args)
    {
        Properties props = new Properties();
        props.put("annotators", "tokenize, ssplit, pos, lemma");
        StanfordCoreNLP pipeline;
        pipeline = new StanfordCoreNLP(props, false);
        String text = "This is my text";
        Annotation document = pipeline.process(text);

        for(CoreMap sentence: document.get(SentencesAnnotation.class))
        {
            for(CoreLabel token: sentence.get(TokensAnnotation.class))
            {
                String word = token.get(TextAnnotation.class);
                String lemma = token.get(LemmaAnnotation.class);
                System.out.println("lemmatized version :" + lemma);
            }
        }
    }
}

编译器向我抛出以下错误

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:558)
at edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:85)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:267)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:129)
at Entry.main(Entry.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by : edu.stanford.nlp.io.RuntimeIOException : Unrecoverable error while loading a tagger model
at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:763)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:294)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:259)
at edu.stanford.nlp.pipeline.POSTaggerAnnotator.loadModel(POSTaggerAnnotator.java:97)
at edu.stanford.nlp.pipeline.POSTaggerAnnotator.<init>(POSTaggerAnnotator.java:77)
at edu.stanford.nlp.pipeline.StanfordCoreNLP$4.create(StanfordCoreNLP.java:556)
... 9 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:446)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:758)
... 14 more

我下载了CoreNLP库的jar文件,并且正在使用Idea IntelliJ。 无法理解错误,有人知道吗?

您可能会丢失* models.jar。 除非内存成为主要问题,否则我发现将完整的corenlp软件包编译到单个jar(包括模型)中是部署StanfordNLP的最简单方法。

简便的方法是克隆git repo并构建jar:

git clone https://github.com/stanfordnlp/CoreNLP.git
cd CoreNLP
ant jar

然后,每次编译和运行时,请确保包括生成的jar:

javac -cp /path/to/javanlp-core.jar my.java

编辑:在我看来, 最简单的方法可能是使用maven进行构建,并将Stanford NLP作为依赖项,但是如果您正在寻找更轻量的选项,那么这可行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM