-
Notifications
You must be signed in to change notification settings - Fork 0
/
PostingParser.py
42 lines (36 loc) · 1.16 KB
/
PostingParser.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
'''
Created on Jun 18, 2013
@author: vinyals
'''
import csv
class PostingParser:
def __init__(self, csvfile):
self.dictReader = csv.DictReader(open(csvfile, 'rb'),delimiter = ',', quotechar = '"')
self.data = []
num_rows = 0
for row in self.dictReader:
self.data.append(row)
num_rows += 1
#if __debug__:
# if(num_rows>1000):
# break
def GetFields(self):
return self.dictReader.fieldnames
def num_total(self):
return len(self.data)
if __name__ == '__main__':
testParser = PostingParser('./data/word.kwlist.alignment.csv')
print testParser.GetFields()
print testParser.num_total()
lol = {}
for i in range(testParser.num_total()):
lol[testParser.data[i]['file']]=1
print len(lol)
num_words = 0
words_gt = {}
for i in range(testParser.num_total()):
if testParser.data[i]['alignment']=='CORR' or testParser.data[i]['alignment']=='MISS':
num_words += 1
words_gt[testParser.data[i]['termid']]=1
print num_words
print len(words_gt)