keywords in NEGATIVE Sentiment using sentiment Analysis(stanfordNLP)

344 views Asked by At

My requirement is to read the input text and undergo sentiment Analysis. If the sentiment analysis is NEGATIVE i should get only the negative keywords used in the context.

The following is the code snippet to achieve the sentiment analysis:

String tweet="the movie is worst";
Properties props = new Properties(); // props.put("pos.model", "D:\Stanford_API's\english-left3words-distsim.tagger"); props.setProperty("annotators", "tokenize, ssplit, pos,lemma,parse, sentiment");

     pipeline = new StanfordCoreNLP(props);

        int mainSentiment = 0;
        if (tweet != null && tweet.length() > 0) {
            int longest = 0;

            Annotation annotation = pipeline.process(tweet);
            for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) 
            {
                Tree tree = sentence.get(SentimentCoreAnnotations.AnnotatedTree.class);
                int sentiment = RNNCoreAnnotations.getPredictedClass(tree);

               SimpleMatrix sd= RNNCoreAnnotations.getNodeVector(tree);

               System.out.println("---sentiment----"+sd.negative().eig());
               //System.out.println("---sd.get(0)----"+sd.get(0));

                String partText = sentence.toString();
                if (partText.length() > longest) 
                {
                    mainSentiment = sentiment;
                    longest = partText.length();
                }

           }
        }

Pls suggest how i can get the keywords from the sentence if the sentiment analysis is NEGATIVE ?

0

There are 0 answers