-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats_from_csv.py
53 lines (46 loc) · 1.53 KB
/
stats_from_csv.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
44
45
46
47
48
49
50
51
52
53
dup_file = file("BugData_duplicates2.tsv")
train_file = file("BugData_train2.tsv")
def getCharNGrams(word,n=3):
return [word[i:i+n] for i in range(len(word)-n+1)]
unique_words = set()
unique_trigrams = set()
total_words = 0
total_trigrams = 0
total_docs = 0
for line in dup_file:
try:
total_docs+=1
line = line.strip().split("\t")
title, desc = line[1], line[2]
title = title.split(" ")
desc = desc.split(" ")
total_words += len(title) + len(desc)
unique_words.update(title+desc)
for word in title+desc:
trigrams = getCharNGrams("#" + word + "#")
unique_trigrams.update(trigrams)
total_trigrams += len(trigrams)
except IndexError:
print line
for line in train_file:
try:
total_docs+=1
line = line.strip().split("\t")
title, desc = line[1], line[2]
title = title.split(" ")
desc = desc.split(" ")
total_words += len(title) + len(desc)
unique_words.update(title+desc)
for word in title+desc:
trigrams = getCharNGrams("#" + word + "#")
unique_trigrams.update(trigrams)
total_trigrams += len(trigrams)
except IndexError:
print line
stats_file = open("BugStats_From_CSV_Files2.txt","w+")
stats_file.write("Total Reports: "+str(total_docs));
stats_file.write("\nTotal Unigrams: "+str(total_words));
stats_file.write("\nUnique Unigrams: "+str(len(unique_words)));
stats_file.write("\nTotal Char-Trigrams: "+str(total_trigrams));
stats_file.write("\nUnique Char-Trigrams: "+str(len(unique_trigrams)));
stats_file.write("\nAverage Unigrams per Report(Title + Desc) "+str( total_words/float(total_docs)));