简单的CoreNLP:ClassNotFoundException

时间:2017-06-09 19:10:07

标签: java exception servlets stanford-nlp libraries

我的简单coreNLP代码正在使用main方法,如下面的代码所示。

    package com.books.servlet;

import edu.stanford.nlp.simple.Document;
import edu.stanford.nlp.simple.Sentence;

public class SimpleCoreNLPDemo {
    public static void main(String[] args) { 

        // Create a document. No computation is done yet.
        Document doc = new Document("add your text here! It can contain multiple sentences.");

        for (Sentence sent : doc.sentences()) {  

            // Will iterate over two sentences
            // We're only asking for words -- no need to load any models yet

            System.out.println("The second word of the sentence '" + sent + "' is " + sent.word(1));

            // When we ask for the lemma, it will load and run the part of speech tagger

            System.out.println("The third lemma of the sentence '" + sent + "' is " + sent.lemma(2));

            // When we ask for the parse, it will load and run the parser
            System.out.println("The parse of the sentence '" + sent + "' is " + sent.parse());

        }
    }
}

然后我在我的网络应用程序中使用了此代码,如下所示。当我执行代码。我得到以下错误和异常

我的网络应用代码

public void me(){

    Document doc = new Document("add your text here! It can contain multiple sentences.");

    for (Sentence sent : doc.sentences()) {  

        // Will iterate over two sentences
        // We're only asking for words -- no need to load any models yet

        System.out.println("The second word of the sentence '" + sent + "' is " + sent.word(1));

        // When we ask for the lemma, it will load and run the part of speech tagger
        System.out.println("The third lemma of the sentence '" + sent + "' is " + sent.lemma(2));

        // When we ask for the parse, it will load and run the parser
        System.out.println("The parse of the sentence '" + sent + "' is " + sent.parse());

} }

Error

enter image description here

  

我已经下载了所有jar文件并添加到构建路径中。它是   使用main方法正常工作

1 个答案:

答案 0 :(得分:0)

我刚解决了这个问题。

我将所有斯坦福简单NLP jar文件复制到目录

  

/ WEB-INF / lib

现在我的代码工作正常。以下是我的简单方法及其输出信息。

public String s = "I like java and python";

public static Set<String> nounPhrases = new HashSet<>();

public void me() {

    Document doc = new Document(" " + s);
    for (Sentence sent : doc.sentences()) {

        System.out.println("The parse of the sentence '" + sent + "' is " + sent.parse());

                }
}

输出

The parse of the sentence 'I like java and python' is (ROOT (S (NP (PRP I)) (VP (VBP like) (NP (NN java) (CC and) (NN python)))))