基于spaCy实现pytextrank对英文短语抽取

news/2024/7/16 8:52:30

1 参考学习网站

# 中文的博客
https://www.5axxw.com/wiki/content/475klz
​
# pytextrank的简单使用
https://spacy.io/universe/project/spacy-pytextrank
https://derwen.ai/docs/ptr/start/

2 安装开发环境

(1)安装python3.8

注意:在python3.6及以下版本,安装pytextrank可能存在问题,我原来用的python3.6没有安装成功。

sudo apt install python3.8

(2) 安装pytextrank

pytextrank是基于spaCy实现的,因此需要安装spaCy。在安装pytextrank时自动安装spaCy,spaCy 是一个 Python 和 CPython 的 NLP 自然语言文本处理库。

pip install pytextrank

安装pytextrand不同的版本对spacy的数据模型会有影响,我安装的版本如下:

python=3.8.0,pytextrank=3.1.1,spacy=3.0.6

3 安装spaCy的数据集和模型

在线安装数据模型会受到网络和网速的限制,一般装不成功。因此,离线下载是最好的办法。

spaCy学习网站

https://spacy.io/models

下载数据模型地址

https://github.com/explosion/spacy-models/releases

离线安装数据模型

# 我用的数据模型是en-core-web-sm=3.0.0,不同的版本要对应不同的版本的spaCy会有影响
pip install en_core_web_sm-3.0.0.tar.gz

4 简单例子

import spacy
# 必须导入pytextrank,虽然表面上没用上,
import pytextrank
​
# example text
text = "Compatibility of systems of linear constraints over the set of natural numbers. Criteria of compatibility of a system of linear Diophantine equations, strict inequations, and nonstrict inequations are considered. Upper bounds for components of a minimal set of solutions and algorithms of construction of minimal generating sets of solutions for all types of systems are given. These criteria and the corresponding algorithms for constructing a minimal supporting set of solutions can be used in solving all the considered types systems and systems of mixed types."
​
# 加载模型和依赖
nlp = spacy.load("en_core_web_sm")
​
# 此处调用“PyTextRank”包
nlp.add_pipe("textrank")
doc = nlp(text)
​
# 读出短语、词频和权重
for phrase in doc._.phrases:
    # 短语
    print(phrase.text)
    # 权重、词频
    print(phrase.rank, phrase.count)
    # 短语的列表
    print(phrase.chunks)

http://www.niftyadmin.cn/n/3745856.html

相关文章

docker安装maven私有仓库(nexus3)

1 下载nexus3 # 不同的版本使用的方法有所不同,建议使用比较稳定的版本 sudo docker pull sonatype/nexus3:3.20.0 2 设置数据卷 # 建立目录 sudo mkdir mvn_repository # 设置文件权限 sudo chmod 777 mvn_repository # 设置目录所有者 sudo chown 用户名:组名 …

error: expected constructor, destructor, or type conversion before '.' token

error: expected constructor, destructor, or type conversion before . token 找了半天原因,原来是犯了基础知识不扎实的错误,C中,全局阈只能声明、初始化变量; 不能用于赋值、运算、调用函数等!!&…

微信小程序调用支付接口支付

https://blog.csdn.net/qishubiao/article/details/80804052

配置和使用Nexus私有仓库

1 仓库类型介绍 hosted,提供本地私库功能的类型; proxy,提供代理其它仓库的类型; group,组合多个仓库为一个地址提供服务的类型。 2 创建blob存储 3 选择仓库类型 选择maven2(hosted)、mave…

ubuntu安装截图工具

1 安装Shutter 1.1 安装Shutter 使用命令安装Shutter,装不上Edit,提示缺少libgoo-canvas-perl包 建议使用软件工具安装 2.2 添加快捷键 快捷方式 Ctrlalta,命令是shutter -s(表示选择区域),也可以是shu…

微信小程序登录时序图

说明: 调用 wx.login() 获取 临时登录凭证code ,并回传到开发者服务器。调用 code2Session 接口,换取 用户唯一标识 OpenID 和 会话密钥 session_key。 之后开发者服务器可以根据用户标识来生成自定义登录态,用于后续业务逻辑中前…

微信小程序中的session_key的使用方法

https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html

微信小程序开放数据校验与解密

https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html