def keywords(self, num=5):
words_only = self.strip_tags(self.content, strip_punctuation=True)
words = words_only.split()
counter = collections.Counter(words)
common = counter.most_common()
keywords = []
INSIGNIFICANT_WORDS = ('should', 'which', 'therefore')
for word in common:
lower_word = word[0].lower()
if len(lower_word) > 4 and lower_word not in INSIGNIFICANT_WORDS:
keywords.append(lower_word)
if len(keywords) >= num:
break
return ", ".join(keywords)
评论列表
文章目录