def AND(self, exlistB): setA = self.mergelist setB = exlistB[:] setB.sort(AdData.exIdCmpFunc) self.mergeCount += 1 setR = [] idxA = idxB = 0 matchCnt = 0 while idxA < len(setA) and idxB < len(setB): A = setA[idxA][0] B = setB[idxB] cmp = AdData.exIdCmpFunc(A, B) if cmp==0: distance = abs(A[3] - B[3]) setR.append((A, distance)) #print setA[idxA] #print type(setA[idxA]) #print setA[idxA][1] #print type(setA[idxA][1]) setA[idxA][1] += distance setA[idxA][2].append( (B[3],B[4]) ) idxA += 1 idxB += 1 matchCnt += 1 elif cmp < 0: idxA += 1 else: idxB += 1 if matchCnt > 0: andlist = [] for i in range(len(self.mergelist)): if len(self.mergelist[i][2]) == self.mergeCount: andlist.append(self.mergelist[i]) #print "==matchCnt=%d, andlist=%d" % (matchCnt, len(andlist)) del self.mergelist self.mergelist = andlist
def __init__(self, exlist): # one item in mergelist = (exinfo, distance, word_position) self.mergelist = map(lambda ex: [ex,0, [(ex[3], ex[4])]], exlist) self.mergelist.sort(lambda x,y: AdData.exIdCmpFunc(x[0],y[0])) self.mergeCount = 1