2014-04-14 9 views
6

मैं ग्रहण में कोरएनएलपी भावना विश्लेषक को लागू करने की कोशिश कर रहा हूं। त्रुटि प्राप्त करना:स्टैनफोर्ड कोरएनएलपी भावना

Unable to resolve "edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz" 

या तो वर्ग पथ, फ़ाइल नाम या यूआरएल के रूप में। मैंने मैवेन का उपयोग करके सभी एनएलपी फाइलों को स्थापित किया है, इसलिए मुझे यकीन नहीं है कि यह कुछ और क्यों ढूंढ रहा है। यहां वह कोड है जिस पर मुझे त्रुटि मिल रही है।

import java.util.Properties; 


import edu.stanford.nlp.ling.CoreAnnotations; 
import edu.stanford.nlp.neural.rnn.RNNCoreAnnotations; 
import edu.stanford.nlp.pipeline.Annotation; 
import edu.stanford.nlp.pipeline.StanfordCoreNLP; 
import edu.stanford.nlp.sentiment.SentimentCoreAnnotations; 
import edu.stanford.nlp.trees.Tree; 
import edu.stanford.nlp.util.CoreMap; 

public class StanfordSentiment { 


StanfordCoreNLP pipeline; 



public StanfordSentiment(){ 
    Properties props = new Properties(); 
    props.setProperty("annotators", "tokenize, ssplit, parse, sentiment"); 

    pipeline = new StanfordCoreNLP(props); 


} 

public float calculateSentiment (String text) { 


     float mainSentiment = 0; 

     int longest = 0; 
     Annotation annotation = pipeline.process(text); 
     for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) { 
      Tree tree = sentence.get(SentimentCoreAnnotations.AnnotatedTree.class); 
      int sentiment = RNNCoreAnnotations.getPredictedClass(tree) - 2; 
      String partText = sentence.toString(); 
      if (partText.length() > longest) { 
       mainSentiment = sentiment; 
       longest = partText.length(); 
      } 

     } 

     return mainSentiment; 



} 
} 
+6

बाहर कर देता है मैं buildpath पर स्टैनफोर्ड-corenlp-3.3.1-models.jar जोड़ने के लिए की जरूरत है और यह काम किया। –

उत्तर

6
public class SentimentAnalysis { 

    public static void main(String[] args) throws IOException { 
     String text = "I am very happy"; 
     Properties props = new Properties(); 
     props.setProperty("annotators", 
       "tokenize, ssplit, pos, lemma, parse, sentiment"); 
     StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 

     Annotation annotation = pipeline.process(text); 
     List<CoreMap> sentences = annotation 
       .get(CoreAnnotations.SentencesAnnotation.class); 
     for (CoreMap sentence : sentences) { 
      String sentiment = sentence 
        .get(SentimentCoreAnnotations.ClassName.class); 
      System.out.println(sentiment + "\t" + sentence); 
     } 
    } 
} 

आशा है कि यह मदद मिलेगी .. :)

संबंधित मुद्दे