首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >StanfordCoreNLP NoSuchMethodError

StanfordCoreNLP NoSuchMethodError
EN

Stack Overflow用户
提问于 2014-06-29 15:06:07
回答 1查看 1.1K关注 0票数 2
代码语言:javascript
复制
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import java.util.Properties;
import java.util.Map;


import edu.stanford.nlp.ling.CoreAnnotations.NamedEntityTagAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.PartOfSpeechAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.TextAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.TokensAnnotation;
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.semgraph.SemanticGraph;
import edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.trees.TreeCoreAnnotations.TreeAnnotation;
import edu.stanford.nlp.util.CoreMap;


public class Stanforder {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        // creates a StanfordCoreNLP object, with POS tagging, lemmatization, NER, parsing, and coreference resolution
        Properties props = new Properties();
        props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
        StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
        String text = "";
        File myFile =  new File("C:\\master\\stanford\\txt\\43711.txt");
        try {
            BufferedReader br = new BufferedReader(new FileReader(myFile));
            try {
                StringBuilder sb = new StringBuilder();
                String line = br.readLine();

                while (line != null) {
                    sb.append(line);
                    //sb.append(System.lineSeparator());
                    line = br.readLine();
                }
                text = sb.toString();
            } catch (Exception e){
                e.printStackTrace();
            } finally {
                try {
                    br.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        } catch(Exception e){
            e.printStackTrace();
        }
        System.out.println(text);
        // read some text in the text variable
         // Add your text here!

        // create an empty Annotation just with the given text
        Annotation document = new Annotation(text);

        // run all Annotators on this text
        pipeline.annotate(document);

        // these are all the sentences in this document
        // a CoreMap is essentially a Map that uses class objects as keys and has values with custom types
        List<CoreMap> sentences = document.get(SentencesAnnotation.class);

        for(CoreMap sentence: sentences) {
          // traversing the words in the current sentence
          // a CoreLabel is a CoreMap with additional token-specific methods
          for (CoreLabel token: sentence.get(TokensAnnotation.class)) {
            // this is the text of the token
            String word = token.get(TextAnnotation.class);
            // this is the POS tag of the token
            String pos = token.get(PartOfSpeechAnnotation.class);
            // this is the NER label of the token
            String ne = token.get(NamedEntityTagAnnotation.class);
          }

          // this is the parse tree of the current sentence
          Tree tree = sentence.get(TreeAnnotation.class);

          // this is the Stanford dependency graph of the current sentence
          SemanticGraph dependencies = sentence.get(CollapsedCCProcessedDependenciesAnnotation.class);
        }

    }

}

这是斯坦福网站的示例,我试图从一个文件中读取内容,在调用StanfordCoreNLP (props)构造函数的行中,我得到了以下异常:

线程"main“中出现异常

edu.stanford.nlp.util.Generics.newHashMap()Ljava/util/Map;:java.lang.NoSuchMethodError在edu.stanford.nlp.pipeline.AnnotatorPool.(AnnotatorPool.java:27) at edu.stanford.nlp.pipeline.StanfordCoreNLP.getDefaultAnnotatorPool(StanfordCoreNLP.java:303) at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:256) at edu.stanford.nlp.pipeline.StanfordCoreNLP.(StanfordCoreNLP.java:129) at edu.stanford.nlp.pipeline.StanfordCoreNLP.(StanfordCoreNLP.java:125) at Stanforder.main(Stanforder.java:35)

任何帮助都是非常感谢的。谢谢!

EN

回答 1

Stack Overflow用户

发布于 2014-07-15 06:55:21

中的第九个问题

http://nlp.stanford.edu/software/corenlp-faq.shtml#nosuchmethoderror

上面写着,

“这是因为您的类路径上还有一个或多个斯坦福NLP工具的旧版本”

同时也看看,

https://mailman.stanford.edu/pipermail/java-nlp-user/2013-November/004357.html

上面写着

显然,有一些jar文件不兼容。您的类路径中有我们工具的旧版本吗?

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24477325

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档