执行和测试stanford核心nlp示例


子阳
2025-02-12 07:27:04 (1月前)
  1. 我下载了


斯坦福
</跨度>
核心

NLP
</跨度>
包,并试图在我的机器上测试它。

使用命令:java -cp“*” - mx1g edu.stanford.nlp.sentiment.SentimentPipeline -file input.txt

我在 注释器标记化中获得了情绪结果
添加注释器ssplit
添加注释器位置
从edu读取POS标记模型/

斯坦福
</跨度>
/

NLP
</跨度>
/模型/ POS-恶搞/英left3wo
rds / english-left3words-distsim.tagger …完成[36.6秒

5 条回复
  1. 0# 记忆只剩空城 | 2019-08-31 10-32



    按照这个例子

    这里

    你需要运行情绪分析。




    1. java -cp “*” -mx5g edu.stanford.nlp.sentiment.SentimentPipeline -file input.txt

    2. </code>


    显然这是一个内存昂贵的操作,它可能不完整只有1千兆字节。
    然后你可以使用“评估工具”




    1. java -cp “*” edu.stanford.nlp.sentiment.Evaluate edu/stanford/nlp/models/sentiment/sentiment.ser.gz input.txt

    2. </code>

  2. 1# 一腔诗意喂了狗 | 2019-08-31 10-32



    这对我来说很好 -



    Maven依赖:





    1. 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

    2. </code>


    Java代码:




    1. 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);

    2.     Annotation annotation = pipeline.process(text);
    3.     List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
    4.     for (CoreMap sentence : sentences) {
    5.         String sentiment = sentence.get(SentimentCoreAnnotations.SentimentClass.class);
    6.         System.out.println(sentiment + "\t" + sentence);
    7.     }
    8. }
    9. </code>


    结果:



    非常积极这个世界是一个了不起的地方


  3. 2# !啊啊 | 2019-08-31 10-32



    您需要将“情绪”注释器添加到注释器列表中:




    1. -annotators tokenize,ssplit,pos,lemma,parse,sentiment

    2. </code>


    这将为XML中的每个句子节点添加“情绪”属性。


  4. 3# 别闹 | 2019-08-31 10-32



    您可以在代码中执行以下操作:




    1. String text = I am feeling very sad and frustrated.”;
      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);
      }

    2. </code>


    它将打印句子和句子本身的情绪,例如: “我感到非常伤心和沮丧。”:




    1. Negative I am feeling very sad and frustrated.

    2. </code>

登录 后才能参与评论