首页 > 编程知识 正文

curseforge客户端中文,textrank相似度

时间:2023-05-03 08:08:14 阅读:33103 作者:759

基于pytextrank英语关键字# pip install pytextrank# 提取的python-mspacydownloaden _ core _ web _ smimportspacyimportpytextranktext=' compatibilityofsystemsoflinearconstrainttext systemoflineardiophantineequations,strict inequations, andnonstrictinequationsareconsidered.upperboundsforcomponentsofaminimalsetofsolutionsandalgorithmsofconstructiononofminimalgenengenengengengenend lltypesofsystemsaregiven.thesecriteriaandthecorrespondingalgorithmsforconstructingaminimalsupportingset olutionscanbeusedinsorion systemsandsystemsofmixedtypes.' # loadaspacymodel,语言设计, scale etc.NLP=spacy.load (en _ core _ web _ sm ) ) addpytextranktothespacypipelinetr=pytextrank.text rank ) ) NLP last=true(doc=NLP(text ) examine the top-rankedphrasesinthedocumentforpindoc._.phrases 3360 print () ) 6533:4 p.text ) (print ) p.chunks )基于Textrank4zh的中文关键字提取(' ' TextRank算法主要包括关键字提取、重要短语提取和重要句子提取。 )1)关键字提取(keyword extraction )关键字提取是指从文本中确定能够描述文档含义的术语的过程。 在关键字提取中,用于构建顶点集的文本单元可以是文中的一个或多个单词; 根据这些单词之间的关系构建边缘。 例如,它同时显示在一个框中。 根据任务需要,可以使用语法过滤器syntactic filters优化顶点集。 语法过滤器的主要作用是过滤某些类型或某些类型的词性字符作为顶点集。 )关键字短语提取) keyphrase extration )关键字提取结束后,得到的n个关键字是原始文本中相邻的关键字构成关键字短语。 因此,从get_keyphrases函数的源代码可以看出,首先调用get_keywords提取关键字,然后分析关键字是否相邻,最后确定关键短语。 )3)重要句子提取(sentence extraction )句子提取任务主要针对自动摘要这一场景,以每个sentence为顶点,根据两个句子之间内容的重叠度来计算他们之间的“相似度”,将这种相似度联系起来,实现在该场景中,将相似度的大小构建为edge ' ' # coding=utf-8 fromtextrank4zhimporttextrank4keyword, text rank4sentenceimportjieba.analysefromsnownlpimportsnownlpimportpandasaspdimportnumpyasnp # 关键字提取def keywords _ extraction (3360 tr4w=text rank4keyword (allow _ speech _ tags=[ ' n '、' nr '、' nrfg '、' ns ' ) vertex_source='all_filters ',edge_source='no_stop_words ',pagerank_connk默认值为2 # lower --英语文本rds_all_filters中的哪一个来构造pagerank对应的图中的节点 # -- 默认值为`'all_filters'`,可选值为`'no_filter', 'no_stop_words', 'all_filters' # edge_source -- 选择使用words_no_filter, words_no_stop_words, words_all_filters中的哪一个来构造pagerank对应的图中的节点之间的边 # -- 默认值为`'no_stop_words'`,可选值为`'no_filter', 'no_stop_words', 'all_filters'`。边的构造要结合`window`参数 # pagerank_config -- pagerank算法参数配置,阻尼系数为0.85 keywords = tr4w.get_keywords(num=6, word_min_len=2) # num -- 返回关键词数量 # word_min_len -- 词的最小长度,默认值为1 return keywords #关键短语抽取def keyphrases_extraction(text): tr4w = TextRank4Keyword() tr4w.analyze(text=text, window=2, lower=True, vertex_source='all_filters', edge_source='no_stop_words', pagerank_config={'alpha': 0.85, }) keyphrases = tr4w.get_keyphrases(keywords_num=6, min_occur_num=1) # keywords_num -- 抽取的关键词数量 # min_occur_num -- 关键短语在文中的最少出现次数 return keyphrases #关键句抽取def keysentences_extraction(text): tr4s = TextRank4Sentence() tr4s.analyze(text, lower=True, source='all_filters') # text -- 文本内容,字符串 # lower -- 是否将英文文本转换为小写,默认值为False # source -- 选择使用words_no_filter, words_no_stop_words, words_all_filters中的哪一个来生成句子之间的相似度。 # -- 默认值为`'all_filters'`,可选值为`'no_filter', 'no_stop_words', 'all_filters' # sim_func -- 指定计算句子相似度的函数 # 获取最重要的num个长度大于等于sentence_min_len的句子用来生成摘要 keysentences = tr4s.get_key_sentences(num=3, sentence_min_len=6) return keysentences def keywords_textrank(text): keywords = jieba.analyse.textrank(text, topK=6) return keywords if __name__ == "__main__": text = "来源:中国科学报本报讯(记者缥缈的香菇)又有一位中国科学家喜获小行星命名殊荣!4月19日下午,中国科学院国家天文台在京举行“周又元星”颁授仪式," "我国天文学家、中国科学院院士周又元的弟子与mydfh在欢声笑语中济济一堂。国家天文台党委书记、" "副台长任性的蛋挞在致辞一开始更是送上白居易的诗句:“令公桃李满天下,粗心的大神前更种花。”" "据介绍,这颗小行星由国家天文台施密特CCD小行星项目组于1997年9月26日发现缓慢的大象观测站," "获得国际永久编号第120730号。2018年9月25日,经国家天文台申报," "国际天文学联合会小天体联合会小天体命名委员会批准,国际天文学联合会《小行星通报》通知国际社会," "正式将该小行星命名为“周又元星”。" #关键词抽取 keywords=keywords_extraction(text) print(keywords) #关键短语抽取 keyphrases=keyphrases_extraction(text) print(keyphrases) #关键句抽取 keysentences=keysentences_extraction(text) print(keysentences)

参考:
https://pypi.org/project/pytextrank/
https://blog.csdn.net/asialee_bird/article/details/96894533

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。