2017-06-09 2 views
0

私の単純なcoreNLPコードは、以下のコードのようにmainメソッドで動作しています。シンプルなCoreNLP:ClassNotFoundException

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

     } 
    } 
} 

次に、このコードをWebアプリケーションで以下のように使用しました。私はコードを実行します。私は、エラーと例外

私のWebアプリケーションコード

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ファイルをダウンロードしたとビルド・パスに追加されます。それは メインメソッドで正常に動作します

答えて

0

私はただ問題を解決しました。

私は、ディレクトリ

/WEB-INF/libに

、今私のコードは正常に動作しているにすべての私のスタンフォード簡単なNLPのjarファイルをコピーしました。以下は私の簡単な方法とその情報です。

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