赞
踩
Python代码实现文本摘要的核心算法有以下几种:
- from collections import Counter
-
- def summarize_text_based_on_word_frequency(text, n=5):
- words = text.split()
- word_counter = Counter(words)
- sorted_words = sorted(word_counter.items(), key=lambda x: x[1], reverse=True)
- top_n_words = [x[0] for x in sorted_words[:n]]
- summary = ' '.join(top_n_words)
- return summary
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。