Exemple #1
0
def getCorpusFilePath():
    r'''Get the stored music21 directory that contains the corpus metadata cache.

    >>> fp = common.getCorpusFilePath()
    >>> fp.endswith('music21/corpus') or fp.endswith(r'music21\corpus')
    True
    '''
    from music21 import corpus
    coreCorpus = corpus.CoreCorpus()
    if coreCorpus.manualCoreCorpusPath is None:
        return os.path.join(getSourceFilePath(), 'corpus')
    return coreCorpus.manualCoreCorpusPath
Exemple #2
0
            nGrams.append(tuple(nGram))
        return nGrams

    def hashNGrams(self, nGrams):
        import collections
        nGramDict = collections.Counter()
        for nGram in nGrams:
            nGramDict[nGram] += 1
        sortedDict = tuple(nGramDict.most_common())
        return sortedDict


if __name__ == '__main__':
    import os
    import json
    coreCorpus = corpus.CoreCorpus()
    paths = [x for x in coreCorpus.getPaths() if 'trecento' in x]
    #paths = paths[:2]
    paths = [os.path.join('trecento', os.path.split(x)[-1]) for x in paths]
    jobs = []
    jobTotal = len(paths)
    for i, path in enumerate(paths):
        job = NGramJob(
            path,
            jobNumber=i,
            jobTotal=jobTotal,
        )
        jobs.append(job)
    processedJobs = NGramJobHandler.execute(jobs)
    processedJobs.sort(key=lambda x: x.filename)
    result = {}