简体   繁体   English

简单的CoreNLP:ClassNotFoundException

[英]Simple CoreNLP : ClassNotFoundException

My simple coreNLP code is working with main method as shown in code below. 我简单的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());

        }
    }
}

Then I used this code in my web application as below. 然后,我在如下的Web应用程序中使用了此代码。 when I execute the code. 当我执行代码时。 I get Below error and exception 我得到以下错误和异常

My web app code 我的网络应用代码

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());

} }

错误

在此处输入图片说明

I have downloaded all the jar files and added to the build path. 我已经下载了所有jar文件并添加到了构建路径。 it is working fine with main method 主要方法很好用

I just resolved the problem. 我刚刚解决了这个问题。

I copied all my Stanford simple NLP jar file to the directory 我将所有斯坦福简单NLP jar文件复制到目录

/WEB-INF/lib / WEB-INF / lib中

and now my code is working fine. 现在我的代码运行正常。 Below is my simple method and its output for your information. 以下是我的简单方法及其输出,供您参考。

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());

                }
}

output 产量

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)))))

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

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