textrank4zh 文本摘要提取

from textrank4zh import TextRank4Keyword,TextRank4Sentence
tr4w = TextRank4Keyword()
tr4w.analyze(text=text, lower=True, window=2)
tr4s = TextRank4Sentence()
tr4s.analyze(text=text, lower=True, source = 'all_filters')
print( '关键词:' )
for item in tr4w.get_keywords(20, word_min_len=1):
    print(item.word, item.weight)
print( '关键短语:' )
for phrase in tr4w.get_keyphrases(keywords_num=20, min_occur_num= 2):
    print(phrase)
print( '摘要:' )
for item in tr4s.get_key_sentences(num=3):
    print(item.index, item.weight, item.sentence)

reference:
https://www.cnblogs.com/chenbjin/p/4600538.html
https://blog.csdn.net/xiaocong1990/article/details/72614430

你可能感兴趣的:(textrank4zh 文本摘要提取)