加载标记模式时出现空指针异常

时间:2014-10-18 09:05:13

标签: java nullpointerexception

public String find_tree(String text){
    String output = "";
    // 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) {
        TokenizerFactory tokenizerFactory = PTBTokenizer.factory(new CoreLabelTokenFactory(), "");
        List wordList = tokenizerFactory.getTokenizer(new StringReader(sentence.toString())).tokenize();
        Tree tree =  sentence.get(TreeAnnotation.class);
        output +=tree.toString();
    }
    return output;
}

当我运行程序时,它会抛出NullPointerException pipeline.annotate(文件); 这里,管道是StanfordCoreNLP对象: 私人StanfordCoreNLP管道; 管道=新的StanfordCoreNLP(道具); // prop是属性对象

// creates a StanfordCoreNLP object, with POS tagging, lemmatization, NER, parsing, and coreference resolution
    prop = new Properties();
    try{
        prop.put("annotators","tokenize, ssplit, pos, lemma, ner, parse, dcoref");
        prop.put("ssplit.eolonly",true);
        pipeline = new StanfordCoreNLP(prop);
    }
    catch(Exception e){System.out.println(e);}

0 个答案:

没有答案