def indexScoreFilePaths(scoreFilePaths, giveUpdates=False, *args, **kwds): ''' Returns a dictionary of the lists from indexScoreParts for each score in scoreFilePaths >>> searchResults = corpus.search('bwv19') >>> fpsNamesOnly = sorted([searchResult.sourcePath for searchResult in searchResults]) >>> len(fpsNamesOnly) 9 >>> scoreDict = search.segment.indexScoreFilePaths(fpsNamesOnly[2:5]) >>> len(scoreDict['bwv190.7.mxl']) 4 >>> scoreDict['bwv190.7.mxl'][0]['measureList'] [(0, 9), (6, 15), (11, 20), (17, 25), (22, 31), (27, 32)] >>> scoreDict['bwv190.7.mxl'][0]['segmentList'][0] 'NNJLNOLLLJJIJLLLLNJJJIJLLJNNJL' ''' if giveUpdates is True: updateFunction = _giveUpdatesMulticore else: updateFunction = None indexFunc = partial(_indexSingleMulticore, *args, **kwds) rpList = common.runParallel(scoreFilePaths, indexFunc, updateFunction) scoreDict = OrderedDict(rpList) return scoreDict
def indexScoreFilePaths(scoreFilePaths, giveUpdates=False, *args, runMulticore=True, **keywords): # noinspection PyShadowingNames ''' Returns a dictionary of the lists from indexScoreParts for each score in scoreFilePaths >>> #_DOCS_SHOW searchResults = corpus.search('bwv190') >>> searchResults = corpus.corpora.CoreCorpus().search('bwv190') #_DOCS_HIDE >>> fpsNamesOnly = sorted([searchResult.sourcePath for searchResult in searchResults]) >>> len(fpsNamesOnly) 2 >>> scoreDict = search.segment.indexScoreFilePaths(fpsNamesOnly) >>> len(scoreDict['bwv190.7.mxl']) 4 >>> scoreDict['bwv190.7.mxl'][0]['measureList'] [(0, 9), (6, 15), (11, 20), (17, 25), (22, 31), (27, 32)] >>> scoreDict['bwv190.7.mxl'][0]['segmentList'][0] 'NNJLNOLLLJJIJLLLLNJJJIJLLJNNJL' ''' if giveUpdates is True: updateFunction = _giveUpdatesMulticore else: updateFunction = None indexFunc = partial(_indexSingleMulticore, *args, **keywords) for i in range(len(scoreFilePaths)): if not isinstance(scoreFilePaths[i], pathlib.Path): scoreFilePaths[i] = pathlib.Path(scoreFilePaths[i]) if runMulticore: rpListUnOrdered = common.runParallel( scoreFilePaths, indexFunc, updateFunction=updateFunction) else: rpListUnOrdered = common.runNonParallel( scoreFilePaths, indexFunc, updateFunction=updateFunction) # ensure that orderedDict is sorted by original scoreFiles rpDict = {} for outShortName, outData, originalPathlib in rpListUnOrdered: rpDict[originalPathlib] = (outShortName, outData) rpList = [] for p in scoreFilePaths: rpList.append(rpDict[p]) scoreDict = OrderedDict(rpList) return scoreDict
def runAll(self): ''' Main routine to run a test -- call after everything has been set. ''' if self.fileList is None: self.fileList = self.getFileList() if self.nrcParsed is None: self.nrcParsed = self.parseNrc() self.clearValues() if self.usePickle and exists(self.resultsFilename() + '.p'): self.readPickleValues() else: output = common.runParallel(self.fileList, self.oneSong, updateFunction=self.update, updateSendsIterable=True) self.calculateValues(output) if self.usePickle: self.pickleValues() toPrint = self.getResultsHeader() for sentimentNumber in range(10): thisFound = self.foundObservations[sentimentNumber] thisNotFound = self.notFoundObservations[sentimentNumber] toPrint += "\nSentiment: " + self.sentimentIntToString( sentimentNumber) + "\t" toPrint += "Occurrence: " + str( self.lyricsWithSentiment[sentimentNumber]) + "\n" # print(deviations[sentimentInt]) if not thisFound: continue # no observations # toPrint += "\n" + str(thisDeviation) toPrint += self.classSpecificResults(thisFound, thisNotFound, sentimentNumber) toPrint += "\n" for sent1, sent2 in itertools.product(range(10), repeat=2): if sent2 <= sent1: continue sent1Obs = self.foundObservations[sent1] sent2Obs = self.foundObservations[sent2] _, pValue = stats.ttest_ind(sent1Obs, sent2Obs, equal_var=False) toPrint += "*** p-value of {:10s} vs. {:10s} is : {:7.5f} \n".format( self.sentimentIntToString(sent1), self.sentimentIntToString(sent2), pValue) toPrint += "*** diff of median of {:10s} - {:10s} is : {} \n\n".format( self.sentimentIntToString(sent1), self.sentimentIntToString(sent2), median(sent1Obs) - median(sent2Obs)) print(toPrint) self.writeFile(toPrint)
def metersParallel(inputPath): mxlfiles = [ path.join(inputPath, f) for f in listdir(inputPath) if (path.isfile(path.join(inputPath, f)) and f[-3:] == "mxl") ] meters = common.runParallel(mxlfiles, checkMeters, updateFunction=update) c = Counter(meters) print(c.most_common())
def indexScoreFilePaths(scoreFilePaths, giveUpdates=False, *args, runMulticore=True, **kwds): ''' Returns a dictionary of the lists from indexScoreParts for each score in scoreFilePaths >>> #_DOCS_SHOW searchResults = corpus.search('bwv190') >>> searchResults = corpus.corpora.CoreCorpus().search('bwv190') #_DOCS_HIDE >>> fpsNamesOnly = sorted([searchResult.sourcePath for searchResult in searchResults]) >>> len(fpsNamesOnly) 2 >>> scoreDict = search.segment.indexScoreFilePaths(fpsNamesOnly) >>> len(scoreDict['bwv190.7.mxl']) 4 >>> scoreDict['bwv190.7.mxl'][0]['measureList'] [(0, 9), (6, 15), (11, 20), (17, 25), (22, 31), (27, 32)] >>> scoreDict['bwv190.7.mxl'][0]['segmentList'][0] 'NNJLNOLLLJJIJLLLLNJJJIJLLJNNJL' ''' if giveUpdates is True: updateFunction = _giveUpdatesMulticore else: updateFunction = None indexFunc = partial(_indexSingleMulticore, *args, **kwds) for i in range(len(scoreFilePaths)): if not isinstance(scoreFilePaths[i], pathlib.Path): scoreFilePaths[i] = pathlib.Path(scoreFilePaths[i]) if runMulticore: rpListUnOrdered = common.runParallel(scoreFilePaths, indexFunc, updateFunction=updateFunction) else: rpListUnOrdered = common.runNonParallel(scoreFilePaths, indexFunc, updateFunction=updateFunction) # ensure that orderedDict is sorted by original scoreFiles rpDict = {} for outShortName, outData, originalPathlib in rpListUnOrdered: rpDict[originalPathlib] = (outShortName, outData) rpList = [] for p in scoreFilePaths: rpList.append(rpDict[p]) scoreDict = OrderedDict(rpList) return scoreDict
def organizeParallel(inputPath, outputPath, categorizeFunctionList): mxlfiles = [ path.join(inputPath, f) for f in listdir(inputPath) if (path.isfile(path.join(inputPath, f)) and f[-3:] == "mxl") ] newOrganizeOneSong = partial(organizeOneSong, outputPath=outputPath, categorizeFunctionList=categorizeFunctionList) unused_output = common.runParallel(mxlfiles, newOrganizeOneSong, updateFunction=update) print("Successfully organized files from path \"" + inputPath + "\".")
def printInfoParallel(inputPath): mxlfiles = [ path.join(inputPath, f) for f in listdir(inputPath) if (path.isfile(path.join(inputPath, f)) and f[-3:] == "mxl") ] toPrint = "Filename\tTitle\t# Chords\t#lyrics\tSyllabic\n" output = common.runParallel(mxlfiles, xmlFileInfo, updateFunction=update) output = sorted(output, key=lambda x: x[1]) infoDict = {} needsReview = [] delete = [] for out in output: key = " ".join([ x.strip().translate(None, string.punctuation) for x in out[1].split() ]) if key in infoDict: diffchords = int(out[2]) - int(infoDict[key][2]) difflyrics = int(out[3]) - int(infoDict[key][3]) if diffchords >= 0 and difflyrics >= 0: if out[4] or out[4] == infoDict[key][4]: delete.append(infoDict[key]) infoDict[key] = out else: needsReview += [infoDict[key], out] elif diffchords <= 0 and difflyrics <= 0: if out[4] and out[4] != infoDict[key][4]: needsReview += [infoDict[key], out] else: delete.append(out) else: needsReview += [infoDict[key], out] else: infoDict[key] = out for st in output: toPrint += "\t".join(st) + "\n" with open("Needs_Review.txt", "w") as res: res.write("\n".join(["\t".join(x) for x in needsReview])) with open("duplicatesToDelete.txt", "w") as res: res.write("\n".join(["\t".join(x) for x in delete]))
def prepare_data(): path_list = [] for midi_file_path in Path(c.SONG_DIR_PATH).glob('**/*.mid'): path_list.append(midi_file_path) common.runParallel(path_list, check_instruments_and_save_notes)