class Load_Corpus_with_Iteration(object): # 使用迭代器读取语料库
def __init__(self, labelPath, scorePath,lineList):
self.labelPath = labelPath
self.scorePath = scorePath
self.lineList = lineList
self.index = 0
self.line = 0
def __iter__(self):
for val in self.lineList:
labelToScore = []
for i in xrange(self.line,self.line+val):
labelToScore.append((float(linecache.getline(self.labelPath, i + 1).strip()),float(linecache.getline(self.scorePath, i + 1).strip())))
self.line+=val
yield labelToScore