You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

10 lines
245 B

import re
from collections import Counter
class WordFrequencyModel:
def get_top_n_words(self, text, top_n=10):
words = re.findall(r'\b\w+\b', text)
word_counts = Counter(words)
return word_counts.most_common(top_n)