示例#1
0
def getUniqMatchesForAllComp(query, betaDir, beta, p, formula, baseline = False):
    ''' This method takes in the masterData, query, compare, beta and p and returns the uniqMatchesList for the entire masterData'''
    if not os.path.exists(betaDir):
        print 'The base director for logging does not exist.. Exiting' + str(betaDir)
        sys.exit()

    dataPerComp = []
    for compData in masterData:
        compName = compData[2]
        fComp = open(os.path.join(betaDir,compName + '.log'), 'a')
        if baseline is False:
            uniqMatchesTrans = rlcs.getUniqMatches(compData[0][0], query, simObject, beta, p, fComp, formula)
        else:
            uniqMatchesTrans = rlcs.getBaselinePatterns(compData[0][0], query, fComp)
        uniqMatchesGT = rlcs.getGTPatterns(compData[1][0], query, fComp)

        dataPerComp.append((uniqMatchesTrans, uniqMatchesGT))
        fComp.close()
    return dataPerComp
def getPatternsInTransInGTPos(masterData, queryList):
    '''
    This function takes in the masterData and queryList and returns pattern wise list of patterns in transcribed data for 
    each composition for the positions of the where there is a pattern in the GT. This is to analyze the errors in the transcription
    '''
    res = []
    for query in queryList:
        qLen = len(query)
        qRes = []
        transQ = []
        for compData in masterData:
            uniqMatchesGT = rlcs.getGTPatterns(compData[1][0],query)
            #print 'In GT for composition ' + str(compData[2] + ':' + str(uniqMatchesGT))

            # getting the onset times of the pattern boundaries
            GTOnsets = compData[1][1] # array of onsets in the ground truth of the composition
            transOnsets = compData[0][1] # array of the onsets in the transcribed data of the composition
            for match in uniqMatchesGT:

                #print 'Working for:' + str(match)

                GTStartIndex = match[0] - 1 # start index of the pattern in the GT
                GTEndIndex = GTStartIndex + qLen - 1 # end index of the pattern in the GT

                #print 'Starting index in GT:' + str(GTStartIndex)
                #print 'Ending index in GT:' + str(GTEndIndex)

                transStartIndex = ut.findClosestIndex(GTOnsets[GTStartIndex], transOnsets, 0, len(transOnsets)-1)
                transEndIndex = ut.findClosestIndex(GTOnsets[GTEndIndex], transOnsets, 0, len(transOnsets)-1)

                #print 'Starting index in Trans:' + str(transStartIndex)
                #print 'Ending index in iTrans:' + str(transEndIndex)
                if compData[0][0][transStartIndex] == 'NA' and  compData[0][0][transStartIndex+1] == 'KI' and compData[0][0][transStartIndex+2] == 'TA' and compData[0][0][transStartIndex+3] == 'TA' and transEndIndex-transStartIndex+1 == 4:
                    print compData[2]
                qRes.append(transEndIndex - transStartIndex + 1)
                transQ.append(compData[0][0][transStartIndex:transEndIndex + 1])
        res.append((query, qRes, transQ))
    return res