Stanford CoreNlp中英文Java API使用方法

       Stanford Nlp是一个比较牛叉的自然语言处理工具,其很多模型都是基于深度学习方法进行训练得到的,准确率比起原来的很多工具有了很大程度的提高。近年来很多开源项目也用到了其中的一些方法。

       最近重拾这个工具做点语义分析的工作,但是发现中文资料比较少,入门比较困难,所以整理一下自己的使用方法,希望对有需要的童鞋能够有点帮助。

       本文主要是讲如何在Java工程中调用Stanford NLP的API。

一.环境准备

       Eclipse或者IDEA,JDK1.8,Apache Maven(注意,3.5及以后的版本都需要Java8环境才能运行,如果不想在Java8运行的话,请使用以前的版本)。

       建立好一个新的Maven工程,在pom文件中加入如下代码:

    <properties>
        <corenlp.version>3.6.0</corenlp.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>edu.stanford.nlp</groupId>
            <artifactId>stanford-corenlp</artifactId>
            <version>${corenlp.version}</version>
        </dependency>

        <dependency>
            <groupId>edu.stanford.nlp</groupId>
            <artifactId>stanford-corenlp</artifactId>
            <version>${corenlp.version}</version>
            <classifier>models</classifier>
        </dependency>

        <dependency>
            <groupId>edu.stanford.nlp</groupId>
            <artifactId>stanford-corenlp</artifactId>
            <version>${corenlp.version}</version>
            <classifier>models-chinese</classifier>
        </dependency>
    </dependencies>


 

        三个依赖包分别是CoreNlp的算法包、英文语料包、中文语料包,由于Maven默认镜像在国外,而Stanford NLP的模型文件很大,因此对网络要求比较高,网速慢的一不小心就time out下载失败了。 解决方法是找一个包含Stanford NLP依赖库的国内镜像,修改Maven的setting,xml中的mirror属性。

二.英文文本的处理

         英文的处理官网也给出了 示例代码,我这里只做一下整合,代码如下:
package edu.zju.cst.krselee.examples.english;

import edu.stanford.nlp.dcoref.CorefChain;
import edu.stanford.nlp.dcoref.CorefCoreAnnotations;
import edu.stanford.nlp.ling.CoreAnnotations;
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.semgra
  • 4
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值