【NLP】Stanfordcorenlp和Stanfordnlp的安装和基本使用

2024-02-16 07:48

本文主要是介绍【NLP】Stanfordcorenlp和Stanfordnlp的安装和基本使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一、stanfordcorenlp安装和使用

1.安装Python包

pip install stanfordcorenlp

2.下载数据文件

https://stanfordnlp.github.io/CoreNLP/index.html#download

 

corenlp

 

下载好后解压,

 

记当前路径为path_or_host

 

另外,将下载的各语种模型文件

也放在解压后的目录path_or_host下

 

3.安装JDK 1.8 和JRE 1.8

Java SE  JDK安装包下载

https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html

Win 64位 JDK1.8

jdk-8u251-windows-x64.exe

 

tips:需要先用邮箱注册一个账号才能下载

 

配置环境:

Java环境的配置

https://blog.csdn.net/weixin_43529904/article/details/88370720

https://jingyan.baidu.com/article/08b6a591bdb18314a80922a0.html

 

检查:

cmd中输入java、 javac、 java -version有对应的信息出现

 

 

报错解决:

https://blog.csdn.net/sunflower_sara/article/details/106473753

Javac不是外部命令

https://blog.csdn.net/tg928600774/article/details/80992683

Java1.7和1.8冲突

https://blog.csdn.net/weinichendian/article/details/78559496

4. Ner

https://nlp.stanford.edu/software/CRF-NER.html

下载stanford-ner-4.0.0.zip

解压

 

5. 示例:

python直接调用


from stanfordcorenlp import StanfordCoreNLPnlp = StanfordCoreNLP(r'.\\stanford_nlp\\stanford-corenlp-4.0.0', lang='en')# sentence = '斯坦福大学自然语言处理包StanfordNLP'sentence = "This is a growing trend particularly in the United States. Oftentimes there are great opportunities for glamping just outside national park boundaries. Yellowstone, Zion National Park, and Yosemite are excellent both for their supreme natural beauty as well as their many prime opportunities for some glamping."print(nlp.word_tokenize(sentence))  # 分词print(nlp.pos_tag(sentence))  # 词性标注print(nlp.ner(sentence))  # 实体识别print(nlp.parse(sentence))  # 语法树print(nlp.dependency_parse(sentence))  # 依存句法nlp.close() # Do not forget to close! The backend server will consume a lot memery.

 

如果用端口模式:

(详细可参考:https://blog.csdn.net/qq_35203425/article/details/80451243)

 

cmd中启动端口

java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000

 

 

Python脚本中用

nlp = StanfordCoreNLP('http://localhost', port=9000)

替换

nlp = StanfordCoreNLP(r'.\\stanford_nlp\\stanford-corenlp-4.0.0', lang='en')

from stanfordcorenlp import StanfordCoreNLPnlp = StanfordCoreNLP('http://localhost', port=9000)# sentence = '斯坦福大学自然语言处理包StanfordNLP'
sentence = "This is a growing trend particularly in the United States. Oftentimes there are great opportunities for glamping just outside national park boundaries. Yellowstone, Zion National Park, and Yosemite are excellent both for their supreme natural beauty as well as their many prime opportunities for some glamping."print(nlp.word_tokenize(sentence))  # 分词
print(nlp.pos_tag(sentence))  # 词性标注
print(nlp.ner(sentence))  # 实体识别
print(nlp.parse(sentence))  # 语法树
print(nlp.dependency_parse(sentence))  # 依存句法nlp.close() # Do not forget to close! The backend server will consume a lot memery.

 

二、Stanfordnlp安装和使用

 

1. 安装python包

pip install stanfordnlp

 

2. 下载数据文件

python中:

import stanfordnlp

stanfordnlp.download('en')

根据提示输入y即可下载数据

我的下载到了 D:\Users\user\stanfordnlp_resources

大小大概270M

 

3. 安装pytorch

需要依赖pytorch 1.0.0以上版本

打开如下链接选择相应的环境和版本的pytorch

https://pytorch.org/get-started/locally/

https://download.pytorch.org/whl/torch_stable.html

 

 

4. 示例代码:

import stanfordnlp

 

# stanfordnlp.download('en')   # This downloads the English models for the neural pipeline

 

nlp = stanfordnlp.Pipeline() # This sets up a default neural pipeline in English

doc = nlp("Barack Obama was born in Hawaii.  He was elected president in 2008.")

doc.sentences[0].print_dependencies()

 

 

 

参考资料:

https://blog.csdn.net/qq_35203425/article/details/80451243

https://blog.csdn.net/qq_40426415/article/details/80994622

 

其他:

python nltk中使用StanfordNER

https://www.jianshu.com/p/f5c893c89c28

这篇关于【NLP】Stanfordcorenlp和Stanfordnlp的安装和基本使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/713945

相关文章

Java中的Cursor使用详解

《Java中的Cursor使用详解》本文介绍了Java中的Cursor接口及其在大数据集处理中的优势,包括逐行读取、分页处理、流控制、动态改变查询、并发控制和减少网络流量等,感兴趣的朋友一起看看吧... 最近看代码,有一段代码涉及到Cursor,感觉写法挺有意思的。注意是Cursor,而不是Consumer

Node.js net模块的使用示例

《Node.jsnet模块的使用示例》本文主要介绍了Node.jsnet模块的使用示例,net模块支持TCP通信,处理TCP连接和数据传输,具有一定的参考价值,感兴趣的可以了解一下... 目录简介引入 net 模块核心概念TCP (传输控制协议)Socket服务器TCP 服务器创建基本服务器服务器配置选项服

mac安装nvm(node.js)多版本管理实践步骤

《mac安装nvm(node.js)多版本管理实践步骤》:本文主要介绍mac安装nvm(node.js)多版本管理的相关资料,NVM是一个用于管理多个Node.js版本的命令行工具,它允许开发者在... 目录NVM功能简介MAC安装实践一、下载nvm二、安装nvm三、安装node.js总结NVM功能简介N

如何使用CSS3实现波浪式图片墙

《如何使用CSS3实现波浪式图片墙》:本文主要介绍了如何使用CSS3的transform属性和动画技巧实现波浪式图片墙,通过设置图片的垂直偏移量,并使用动画使其周期性地改变位置,可以创建出动态且具有波浪效果的图片墙,同时,还强调了响应式设计的重要性,以确保图片墙在不同设备上都能良好显示,详细内容请阅读本文,希望能对你有所帮助...

Rust中的注释使用解读

《Rust中的注释使用解读》本文介绍了Rust中的行注释、块注释和文档注释的使用方法,通过示例展示了如何在实际代码中应用这些注释,以提高代码的可读性和可维护性... 目录Rust 中的注释使用指南1. 行注释示例:行注释2. 块注释示例:块注释3. 文档注释示例:文档注释4. 综合示例总结Rust 中的注释

python安装whl包并解决依赖关系的实现

《python安装whl包并解决依赖关系的实现》本文主要介绍了python安装whl包并解决依赖关系的实现,文中通过图文示例介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面... 目录一、什么是whl文件?二、我们为什么需要使用whl文件来安装python库?三、我们应该去哪儿下

MySQL安装时initializing database失败的问题解决

《MySQL安装时initializingdatabase失败的问题解决》本文主要介绍了MySQL安装时initializingdatabase失败的问题解决,文中通过图文介绍的非常详细,对大家的学... 目录问题页面:解决方法:问题页面:解决方法:1.勾选红框中的选项:2.将下图红框中全部改为英

Python中多线程和多进程的基本用法详解

《Python中多线程和多进程的基本用法详解》这篇文章介绍了Python中多线程和多进程的相关知识,包括并发编程的优势,多线程和多进程的概念、适用场景、示例代码,线程池和进程池的使用,以及如何选择合适... 目录引言一、并发编程的主要优势二、python的多线程(Threading)1. 什么是多线程?2.

MySQL9.0默认路径安装下重置root密码

《MySQL9.0默认路径安装下重置root密码》本文主要介绍了MySQL9.0默认路径安装下重置root密码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们... 目录问题描述环境描述解决方法正常模式下修改密码报错原因问题描述mysqlChina编程采用默认安装路径,

Linux使用cut进行文本提取的操作方法

《Linux使用cut进行文本提取的操作方法》Linux中的cut命令是一个命令行实用程序,用于从文件或标准输入中提取文本行的部分,本文给大家介绍了Linux使用cut进行文本提取的操作方法,文中有详... 目录简介基础语法常用选项范围选择示例用法-f:字段选择-d:分隔符-c:字符选择-b:字节选择--c