-
Notifications
You must be signed in to change notification settings - Fork 0
/
speechLengthData.py
45 lines (31 loc) · 1.04 KB
/
speechLengthData.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
42
43
# compiles information regarding speech length, removes all speeches with less that 100 words.
# less than was used in the final analysis.
import os as os
import re
import csv
path="/home/dvasques/Desktop/Temp/speech-data/"
def group_items(lst):
res = {}
reg = re.compile("^(..).*")
for item in lst:
match = reg.match(item)
res.setdefault(match.group(1), []).append(item)
return len(res.values())
f=open ('/home/dvasques/Desktop/speechLengthsGT150-.csv', 'wb')
writer = csv.writer(f)
mpList = os.listdir(path)
for mp in mpList:
print (mp)
yearFiles = os.listdir(path+mp)
for mpFile in yearFiles:
fileName = path + mp + "/" + mpFile
#print mpFile
num_words=0
with open(fileName, 'r') as f:
for line in f:
words = line.split()
num_words += len(words)
if(num_words<150):
os.remove(path + mp + "/" + mpFile)
# print (path + mp + "/" + mpFile)
writer.writerow([ mpFile] + [num_words])