在Eclipse下安装和使用Stanford CoreNLP

下载:

  1. coreNLP的包,五百多M大小,主要包括这个算法的很多核心jar包。
    网址:https://stanfordnlp.github.io/CoreNLP/index.html#download
    在这里插入图片描述
    【Download CoreNLP 3.9.2】选这个下载就好了,想下载老的版本可以去蓝色的history page看看。

  2. 适配的中文包(或者其他语言也?️)
    网址:https://stanfordnlp.github.io/CoreNLP/index.html#download
    在这里插入图片描述
    选择对应的语言点击下载就可以了。

移动:

  1. 将stanford-corenlp-full-2018-10-05解压。
    在这里插入图片描述
  2. 把下载好的stanford-chinese-corenlp-2018-10-05-models.jar包添加到stanford-corenlp-full-2018-10-05文件夹的根目录下。
    在这里插入图片描述

开始用Eclipse测试:

  1. 创建一个新的project
    (如果可以的话JRE可以选第二个某些程度上边面JNI报错,其实也许差别不大)
    在这里插入图片描述
  2. stanford-corenlp-full-2018-10-05文件夹内的所有Jar包导入到project中。
    右键project
    – properties
    – Libraries
    – Add External JARs
    – ctrl+a所有*jar就OK了
    –apply
    在这里插入图片描述
  3. 弄了一个叫做Test的包,在里面才建的class。
package Test;

import java.util.List;
import java.util.Map;
import java.util.Properties;

import edu.stanford.nlp.dcoref.CorefChain;
import edu.stanford.nlp.dcoref.CorefCoreAnnotations.CorefChainAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.LemmaAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.NamedEntityTagAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.PartOfSpeechAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.TextAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.TokensAnnotation;
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.semgraph.SemanticGraph;
import edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation;
import edu.stanford.nlp.sentiment.SentimentCoreAnnotations;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.trees.TreeCoreAnnotations.TreeAnnotation;
import edu.stanford.nlp.util.CoreMap;

public class TestCoreNLP2 {
    public static void main(String[] args) {
    	 String props="StanfordCoreNLP-chinese.properties";
    	 	StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
    	 	Annotation annotation;
    	 	annotation = new Annotation("我上辈子肯定是珍珠奶茶!");

    		pipeline.annotate(annotation);
    		pipeline.prettyPrint(annotation, System.out);
    }
}

终于没有遇到bug了。
运行结果如下:
在这里插入图片描述
IN ADDITION,其实在之前我遇到过令人匪夷所思的报错

A JNI error has occurred, please check your installation and try again

后面发现是之前用的代码有问题,但是如果也有遇到同样错误,解决方法大致就是去加一个新的jcommander-1.78.jar包,加入方法和前面一样。
网址:https://download.csdn.net/download/weixin_43525427/11662148

发布了22 篇原创文章 · 获赞 18 · 访问量 7190

猜你喜欢

转载自blog.csdn.net/weixin_43525427/article/details/100535433