summaryrefslogtreecommitdiff
path: root/app/WordFreq.py
blob: 3620a414dcfe81b4984f7beb442461dc9b1ee046 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
###########################################################################
# Copyright 2019 (C) Hui Lan <hui.lan@cantab.net>
# Written permission must be obtained from the author for commercial uses.
###########################################################################

from wordfreqCMD import remove_punctuation, freq, sort_in_descending_order
import string

class WordFreq:
    def __init__(self, s):
        self.s = remove_punctuation(s)

    def get_freq(self):
        lst = []
        for t in freq(self.s):
            word = t[0]
            if len(word) > 0 and word[0] in string.ascii_letters:
                lst.append(t)
        return sort_in_descending_order(lst)
    

if __name__ == '__main__':
    f = WordFreq('BANANA; Banana, apple ORANGE Banana banana.')
    print(f.get_freq())