栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python使用spacy做关键词提取

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python使用spacy做关键词提取

这是一个最简单的例子,对一篇英文文章提取关键词,不涉及词性分析等。

# -*- coding: utf-8 -*-
# @Author  : meng_zhihao
# @Email   : 312141830@qq.com
# @File    : text-rank.py
import spacy
import pytextrank  # 这行要加

# load a spaCy model, depending on language, scale, etc.
# python -m spacy download en
nlp = spacy.load("en_core_web_sm")  # 导入模块是最耗时的,所以做成服务的时候要避免重复导入! 这个是middle包,可以试试en_core_web_lg

# 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."
with open('5.txt')as f:
    text = f.read()

# add PyTextRank to the spaCy pipeline
nlp.add_pipe("textrank")
doc = nlp(text)

words = []
# examine the top-ranked phrases in the document
for phrase in doc._.phrases:
    # print(phrase.rank, phrase.count)
    print(phrase.chunks[0])
    words.append(phrase.chunks[0])

print(words)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/740919.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号