Executing and testing stanford core nlp example

前端 未结 4 1497
南笙
南笙 2020-12-30 08:46

I downloaded stanford core nlp packages and tried to test it on my machine.

Using command: java -cp \"*\" -mx1g edu.stanford.nlp.sentiment.SentimentPipeline -f

4条回答
  •  长发绾君心
    2020-12-30 09:03

    This is working fine for me -

    Maven Dependencies :

            
                edu.stanford.nlp
                stanford-corenlp
                3.5.2
                models
            
            
                edu.stanford.nlp
                stanford-corenlp
                3.5.2
            
            
                edu.stanford.nlp
                stanford-parser
                3.5.2
            
    

    Java Code :

    public static void main(String[] args) throws IOException {
            String text = "This World is an amazing place";
            Properties props = new Properties();
            props.setProperty("annotators", "tokenize, ssplit, pos, lemma, parse, sentiment");
            StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
    
            Annotation annotation = pipeline.process(text);
            List sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
            for (CoreMap sentence : sentences) {
                String sentiment = sentence.get(SentimentCoreAnnotations.SentimentClass.class);
                System.out.println(sentiment + "\t" + sentence);
            }
        }
    

    Results :

    Very positive This World is an amazing place

提交回复
热议问题