-
Notifications
You must be signed in to change notification settings - Fork 2
/
WordCount.py
41 lines (31 loc) · 873 Bytes
/
WordCount.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from __future__ import print_function
import pysolr
from nltk.parse import stanford
import sys
import nltk
import glob
import os
from nltk.tokenize import sent_tokenize
from nltk.tokenize import WordPunctTokenizer
import string
# Counts the number of words in the corpus
#
# Authors: Shreya Vishwanath Rao, Nanditha Valsaraj, Ramya Elangovan
# Version 1.0: 12/5/2017
if(sys.argv):
datafile=open(sys.argv[1], 'r');
text =datafile.read()
#split to articles
a=text.split('\n\n')
count=0
for i in range(0,len(a)):
#split into sentences
sent_all = sent_tokenize(a[i])
words = WordPunctTokenizer()
for j in range(0, len(sent_all)):
wrds = words.tokenize(sent_all[j])
for k in (wrds):
if k in string.punctuation:
continue
count = count + 1
print(count)