Python中使用Stanford CoreNLP

本文介绍如何使用StanfordNLP的Python封装工具进行自然语言处理任务,包括安装配置、基本使用方法及多语言支持等内容。

前言

Stanford CoreNLP的源代码是使用Java写的,提供了Server方式进行交互。stanfordcorenlp是一个对Stanford CoreNLP进行了封装的Python工具包,GitHub地址,使用非常方便。
***************更新**************
Stanford 官方发布了python版,直接可以安装。具体参见https://stanfordnlp.github.io/stanfordnlp/。
pip install stanfordnlp

安装依赖

1:下载安装JDK 1.8及以上版本。
2:下载Stanford CoreNLP文件,解压。
3:处理中文还需要下载中文的模型jar文件,然后放到stanford-corenlp-full-2018-02-27根目录下即可(注意一定要下载这个文件,否则它默认是按英文来处理的)。

常用接口

StanfordCoreNLP官网给出了python调用StanfordCoreNLP的接口。


Python packages using the Stanford CoreNLP server

These packages use the Stanford CoreNLP server that we’ve developed over the last couple of years. You should probably use one of them.

  • stanfordcorenlp by Lynten Guo. A Python wrapper to Stanford CoreNLP server, version 3.8.0. Also: PyPI page.
  • pycorenlp, A Python wrapper for Stanford CoreNLP by Smitha Milli that uses the new CoreNLP v3.6+ server. Available on PyPI.
  • corenlp-pywrap by Sherin Thomas also uses the new CoreNLP v3.6+ server. Python 3.x (only). Also: PyPI page.
  • Stanford CoreNLP Python Interface: A reference implementation of a Python interface to the Stanford CoreNLP server. By Arun Chaganty. PyPI page.
  • pynlp ,A (Pythonic) Python wrapper for Stanford CoreNLP by Sina. PyPI page.
  • NLTK since version 3.2.3 has a new interface to Stanford CoreNLP using the StanfordCoreNLPServer. Among other places, see instructions on using the dependency parser and the code for this module, and if you poke around the documentation, you can find equivalent interfaces to other CoreNLP components; for example here is Stanford CoreNLP NER. Much of the work for this was done by Dmitrijs Milajevs.

补充

Stanford官方发布了Python版的nlp处理工具,不在纠结使用java了。

Setup

StanfordNLP supports Python 3.6 or later. We strongly recommend that you install StanfordNLP from PyPI. If you already have pip installed, simply run

pip install stanfordnlp

this should also help resolve all of the dependencies of StanfordNLP, for instance PyTorch 1.0.0 or above.
Alternatively, you can also install from source of this git repository, which will give you more flexibility in developing on top of StanfordNLP and training your own models. For this option, run

git clone git@github.com:stanfordnlp/stanfordnlp.git
cd stanfordnlp
pip install -e .
Running StanfordNLP

Getting Started with the neural pipeline
To run your first StanfordNLP pipeline, simply following these steps in your Python interactive interpreter:

>>> import stanfordnlp
>>> stanfordnlp.download('en')   # This downloads the English models for the neural pipeline
>>> nlp 
评论 58
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值