summaryrefslogtreecommitdiff
path: root/app/WordFreq.py
diff options
context:
space:
mode:
authorHui Lan <lanhui@zjnu.edu.cn>2019-11-01 20:51:19 +0800
committerHui Lan <lanhui@zjnu.edu.cn>2019-11-01 20:51:19 +0800
commita8f6a99bb3d3dba85705ed7df93145c28168d659 (patch)
treeb21a324eb857b0b236ea76f22692e18420258e45 /app/WordFreq.py
englishpal: first commit
Diffstat (limited to 'app/WordFreq.py')
-rw-r--r--app/WordFreq.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/app/WordFreq.py b/app/WordFreq.py
new file mode 100644
index 0000000..18f2c49
--- /dev/null
+++ b/app/WordFreq.py
@@ -0,0 +1,20 @@
+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())
+