• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python corpus.search函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中music21.corpus.search函数的典型用法代码示例。如果您正苦于以下问题:Python search函数的具体用法?Python search怎么用?Python search使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了search函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: corpusMelodicIntervalSearch

def corpusMelodicIntervalSearch(show = True):
    # this version compares china to netherlands
    from music21 import corpus
    from music21.analysis import discrete

    mid = discrete.MelodicIntervalDiversity()
    groupEast = corpus.search('shanxi', 'locale')
    groupWest = corpus.search('niederlande', 'locale') 

    msg = []
    for name, group in [('shanxi', groupEast), ('niederlande', groupWest)]:
        intervalDict = {}
        workCount = 0
        intervalCount = 0
        seventhCount = 0
        for fp, n in group:
            workCount += 1
            s = converter.parse(fp, number=n)
            intervalDict = mid.countMelodicIntervals(s, found=intervalDict)
        
        for key in sorted(intervalDict.keys()):
            intervalCount += intervalDict[key][1] # second value is count
            if key in ['m7', 'M7']:
                seventhCount += intervalDict[key][1] 

        pcentSevenths = round(((seventhCount / float(intervalCount)) * 100), 4)
        msg.append('locale: %s: found %s percent melodic sevenths, out of %s intervals in %s works' % (name, pcentSevenths, intervalCount, workCount))
#         for key in sorted(intervalDict.keys()):
#             print intervalDict[key]

    for sub in msg: 
        if show == True:
            print sub
开发者ID:msampaio,项目名称:music21,代码行数:33,代码来源:smt2010.py


示例2: corpusMelodicIntervalSearchBrief

def corpusMelodicIntervalSearchBrief(show=False):
    # try for the most concise representation
    from music21 import corpus, analysis
    mid = analysis.discrete.MelodicIntervalDiversity()
    msg = []
    for region in ['shanxi', 'fujian']:
        intervalDict = {}
        workCount = 0
        intervalCount = 0
        seventhCount = 0
        for fp, n in corpus.search(region, 'locale'):
            workCount += 1
            s = converter.parse(fp, number=n)
            intervalDict = mid.countMelodicIntervals(s, found=intervalDict)
        for key in intervalDict.keys():
            intervalCount += intervalDict[key][1] # second value is count
            if key in ['m7', 'M7']:
                seventhCount += intervalDict[key][1]


        pcentSevenths = round((seventhCount / float(intervalCount) * 100), 4)

        msg.append('locale: %s: found %s percent melodic sevenths, out of %s intervals in %s works' % (region, pcentSevenths, intervalCount, workCount))

    if show == True:
        for sub in msg: 
            print sub
开发者ID:msampaio,项目名称:music21,代码行数:27,代码来源:smt2010.py


示例3: testSearch12

 def testSearch12(self):
     # searching virtual entries
     searchResults = corpus.search('coltrane', field='composer')
     self.assertEqual(len(searchResults) > 0, True)
     # returns items in pairs: url and work number
     self.assertEqual(searchResults[0].sourcePath,
         'http://impromastering.com/uploads/transcription_file/file/196/Giant_Steps__John_Coltrane_C.xml')
开发者ID:EQ4,项目名称:music21,代码行数:7,代码来源:testCorpus.py


示例4: corpusMelodicIntervalSearchBrief

def corpusMelodicIntervalSearchBrief(show=False):
    # try for the most concise representation
    from music21 import corpus, analysis
    melodicIntervalDiversity = analysis.discrete.MelodicIntervalDiversity()
    message = []
    for region in ['shanxi', 'fujian']:
        intervalDict = {}
        workCount = 0
        intervalCount = 0
        seventhCount = 0
        for metadataEntry in corpus.search(region, field='locale'):
            workCount += 1
            score = corpus.parse(
                metadataEntry.sourcePath,
                number=metadataEntry.number,
                )
            intervalDict = melodicIntervalDiversity.countMelodicIntervals(
                score, found=intervalDict)
        for key in intervalDict.keys():
            intervalCount += intervalDict[key][1] # second value is count
            if key in ['m7', 'M7']:
                seventhCount += intervalDict[key][1]
        pcentSevenths = round((seventhCount / float(intervalCount) * 100), 4)
        message.append('locale: %s: found %s percent melodic sevenths, out of %s intervals in %s works' % (region, pcentSevenths, intervalCount, workCount))
    if show == True:
        for sub in message: 
            print (sub)
开发者ID:Aminor7,项目名称:music21,代码行数:27,代码来源:smt2010.py


示例5: testSearch03

 def testSearch03(self):
     searchResults = corpus.search('Taiwan', field='locale')
     self.assertEqual(len(searchResults), 27)
     pathInfo = sorted((str(searchResult.sourcePath), searchResult.number)
         for searchResult in searchResults)
     self.assertEqual(pathInfo, [
         ('essenFolksong/han1.abc', '269'),
         ('essenFolksong/han1.abc', '270'),
         ('essenFolksong/han1.abc', '271'),
         ('essenFolksong/han1.abc', '272'),
         ('essenFolksong/han1.abc', '273'),
         ('essenFolksong/han1.abc', '274'),
         ('essenFolksong/han1.abc', '335'),
         ('essenFolksong/han1.abc', '528'),
         ('essenFolksong/han1.abc', '529'),
         ('essenFolksong/han1.abc', '530'),
         ('essenFolksong/han2.abc', '204'),
         ('essenFolksong/han2.abc', '205'),
         ('essenFolksong/han2.abc', '206'),
         ('essenFolksong/han2.abc', '207'),
         ('essenFolksong/han2.abc', '208'),
         ('essenFolksong/han2.abc', '209'),
         ('essenFolksong/han2.abc', '210'),
         ('essenFolksong/han2.abc', '211'),
         ('essenFolksong/han2.abc', '212'),
         ('essenFolksong/han2.abc', '213'),
         ('essenFolksong/han2.abc', '214'),
         ('essenFolksong/han2.abc', '215'),
         ('essenFolksong/han2.abc', '216'),
         ('essenFolksong/han2.abc', '217'),
         ('essenFolksong/han2.abc', '218'),
         ('essenFolksong/han2.abc', '219'),
         ('essenFolksong/han2.abc', '220'),
         ])
开发者ID:cuthbertLab,项目名称:music21,代码行数:34,代码来源:testCorpus.py


示例6: xtestEx04

    def xtestEx04(self):
        # what

        scSrc = scale.MajorScale()

        niederlande = corpus.search('niederlande', field='locale')

        results = {}
        for unused_name, group in [('niederlande', niederlande)]:
            workCount = 0

            for fp, n in group:
                workCount += 1
    
                s = converter.parse(fp, number=n)
    
                # derive a best-fit concrete major scale
                scFound = scSrc.derive(s)

                # if we find a scale with no unmatched pitches
                if len(scFound.match(s)['notMatched']) == 0:
                    # find out what pitches in major scale are not used
                    post = scFound.findMissing(s)
                    for p in post:
                        degree = scFound.getScaleDegreeFromPitch(p)
                        if degree not in results.keys():
                            results[degree] = 0
                        results[degree] += 1

        print ('Of %s works, the following major scale degrees are not used the following number of times:' % workCount)
        print (results)
开发者ID:Wajih-O,项目名称:music21,代码行数:31,代码来源:icmc2011.py


示例7: corpusFindMelodicSevenths

def corpusFindMelodicSevenths(show = True):
    # find and display melodic sevenths
    import os
    from music21 import corpus
    from music21.analysis import discrete

    mid = discrete.MelodicIntervalDiversity()
    groupEast = corpus.search('shanxi', 'locale')
    groupWest = corpus.search('niederlande', 'locale') 

    found = []
    for name, group in [('shanxi', groupEast), ('niederlande', groupWest)]:
        for fp, n in group:
            s = converter.parse(fp, number=n)
            intervalDict = mid.countMelodicIntervals(s)
        
            for key in sorted(intervalDict.keys()):
                if key in ['m7', 'M7']:
                    found.append([fp, n, s])
                   
    results = stream.Stream()
    for fp, num, s in found: 
        environLocal.printDebug(['working with found', fp, num])
        # this assumes these are all monophonic
        noteStream = s.flat.getElementsByClass('Note')
        for i, n in enumerate(noteStream):
            if i <= len(noteStream) - 2:
                nNext = noteStream[i+1]
            else:
                nNext = None

            if nNext is not None:
                #environLocal.printDebug(['creating interval from notes:', n, nNext, i])
                i = interval.notesToInterval(n, nNext)
                environLocal.printDebug(['got interval', i.name])
                if i.name in ['m7', 'M7']:
                    #n.addLyric(s.metadata.title)
                    junk, fn = os.path.split(fp)
                    n.addLyric('%s: %s' % (fn, num))

                    m = noteStream.extractContext(n, 1, 2, forceOutputClass=stream.Measure)
                    m.makeAccidentals()
                    m.timeSignature = m.bestTimeSignature()
                    results.append(m)
    if show == True:
        results.show()
开发者ID:msampaio,项目名称:music21,代码行数:46,代码来源:smt2010.py


示例8: testExamplesC

    def testExamplesC(self):

        from music21 import corpus, analysis, converter
        # Get an analysis tool
        mid = analysis.discrete.MelodicIntervalDiversity()
        results = []
        # Iterate over two regions
        for region in ['shanxi', 'fujian']:
            # Create storage units
            intervalDict = {}
            workCount = 0
            intervalCount = 0
            seventhCount = 0
            # Perform a location search on the corpus and iterate over 
            # resulting file name and work number
            for fp, n in corpus.search(region, 'locale'):
                workCount += 1
                # Parse the work and create a dictionary of intervals
                s = converter.parse(fp, number=n)
                intervalDict = mid.countMelodicIntervals(s, found=intervalDict)
            # Iterate through all intervals, and count totals and sevenths
            for label in intervalDict.keys():
                intervalCount += intervalDict[label][1] 
                if label in ['m7', 'M7']:
                    seventhCount += intervalDict[label][1]
            # Calculate a percentage and store results
            pcentSevenths = round((seventhCount / float(intervalCount) * 100), 
                            4)
            results.append((region, pcentSevenths, intervalCount, workCount))
    
        # Print results
        for region, pcentSevenths, intervalCount, workCount in results: 
            print('locale: %s: found %s percent melodic sevenths, out of %s intervals in %s works' % (region, pcentSevenths, intervalCount, workCount))

        region, pcentSevenths, intervalCount, workCount = results[0]
        self.assertEqual(region, 'shanxi')
        self.assertEqual(pcentSevenths, 3.1994)
        self.assertEqual(intervalCount, 4282)
        self.assertEqual(workCount, 77)

        region, pcentSevenths, intervalCount, workCount = results[1]
        self.assertEqual(region, 'fujian')
        self.assertEqual(pcentSevenths, 0.7654)
        self.assertEqual(intervalCount, 2613)
        self.assertEqual(workCount, 53)
开发者ID:bewest,项目名称:music21-bewest.clone,代码行数:45,代码来源:testDocumentation.py


示例9: testSearch03

 def testSearch03(self):
     searchResults = corpus.search("Taiwan", field="locale")
     self.assertEqual(len(searchResults), 27)
     pathInfo = sorted((searchResult.sourcePath, searchResult.number) for searchResult in searchResults)
     self.assertEqual(
         pathInfo,
         [
             (u"essenFolksong/han1.abc", u"269"),
             (u"essenFolksong/han1.abc", u"270"),
             (u"essenFolksong/han1.abc", u"271"),
             (u"essenFolksong/han1.abc", u"272"),
             (u"essenFolksong/han1.abc", u"273"),
             (u"essenFolksong/han1.abc", u"274"),
             (u"essenFolksong/han1.abc", u"335"),
             (u"essenFolksong/han1.abc", u"528"),
             (u"essenFolksong/han1.abc", u"529"),
             (u"essenFolksong/han1.abc", u"530"),
             (u"essenFolksong/han2.abc", u"204"),
             (u"essenFolksong/han2.abc", u"205"),
             (u"essenFolksong/han2.abc", u"206"),
             (u"essenFolksong/han2.abc", u"207"),
             (u"essenFolksong/han2.abc", u"208"),
             (u"essenFolksong/han2.abc", u"209"),
             (u"essenFolksong/han2.abc", u"210"),
             (u"essenFolksong/han2.abc", u"211"),
             (u"essenFolksong/han2.abc", u"212"),
             (u"essenFolksong/han2.abc", u"213"),
             (u"essenFolksong/han2.abc", u"214"),
             (u"essenFolksong/han2.abc", u"215"),
             (u"essenFolksong/han2.abc", u"216"),
             (u"essenFolksong/han2.abc", u"217"),
             (u"essenFolksong/han2.abc", u"218"),
             (u"essenFolksong/han2.abc", u"219"),
             (u"essenFolksong/han2.abc", u"220"),
         ],
     )
开发者ID:fzalkow,项目名称:music21,代码行数:36,代码来源:testCorpus.py


示例10: testSearch05

 def testSearch05(self):
     searchResults = corpus.search("bach")
     self.assertEqual(len(searchResults) > 120, True)
开发者ID:fzalkow,项目名称:music21,代码行数:3,代码来源:testCorpus.py


示例11: _compute_PCs

def _compute_PCs(out_fp):
    """Computes pitch class per measure principal components."""
    bachBundle = corpus.search('bwv')
    bachBundle = bachBundle.search('4/4')

    # NOTE: we should refactor this into a separate helper function: music21 Stream -> Pitch class histogram
    index =0
    data = {}
    for n in range(len(bachBundle)):
        data[n] = {}
        for i in range(30,100):
            data[n][i] = 0

    for n in range(len(bachBundle)):
        myPiece = bachBundle[n].parse()

        for m in myPiece.flat.getElementsByClass('Note'):
            data[n][m.midi] +=1

        print 'Number %i' % n

    new_data = np.array([data[0].values()]).astype(np.float64)
    new_data /= np.sum(new_data)

    for index in range(len(bachBundle)):
        temp = np.array([data[index].values()]).astype(np.float64)
        temp /= np.sum(temp)
        new_data =  np.concatenate((new_data,  temp)  , axis=0)

    print 'Statistics gathered!'
    save = new_data

###############################################################################
    bachBundle = corpus
    bachBundle = bachBundle.search('4/4')

    index =0
    data = {}
    for n in range(700, 2500):
        data[n] = {}
        for i in range(30,100):
            data[n][i] = 0

    for n in range(700, 2500):
        myPiece = bachBundle[n].parse()

        for m in myPiece.flat.getElementsByClass('Note'):
                data[n][m.midi] +=1

        print 'Number %i' % n

    new_data = np.array([data[700].values()])
    new_data /= np.sum(new_data)

    for index in range(700, 2500):
        temp = np.array([data[index].values()]).astype(np.float64)
        temp /= np.sum(temp)

        new_data =  np.concatenate( (new_data,  temp )  , axis=0)

    print 'Statistics gathered!'

    X = new_data
    d = np.concatenate((save,X))
    n_components=2
    pca = PCA(n_components=n_components).fit(d)
    pca.components_.tofile(out_fp)

    print '{} PCs written to {}'.format(n_components, out_fp)
开发者ID:feynmanliang,项目名称:bachbot,代码行数:69,代码来源:score.py


示例12: testSearch11

 def testSearch11(self):
     searchResults = corpus.search('mode phry(.*)', field='keySignature')
     self.assertEqual(len(searchResults) >= 9, True)
开发者ID:EQ4,项目名称:music21,代码行数:3,代码来源:testCorpus.py


示例13: testSearch06

 def testSearch06(self):
     searchResults = corpus.search('haydn', field='composer')
     self.assertEqual(len(searchResults), 0)
     searchResults = corpus.search('haydn|bach', field='composer')
     self.assertEqual(len(searchResults) >= 16, True)
开发者ID:cuthbertLab,项目名称:music21,代码行数:5,代码来源:testCorpus.py


示例14: testSearch02

 def testSearch02(self):
     searchResults = corpus.search("Sichuan", field="locale")
     self.assertEqual(len(searchResults), 47)
开发者ID:fzalkow,项目名称:music21,代码行数:3,代码来源:testCorpus.py


示例15: testSearch10

    def testSearch10(self):
        from music21 import key

        ks = key.KeySignature(3)
        searchResults = corpus.search(str(ks), field="keySignature")
        self.assertEqual(len(searchResults) >= 32, True, len(searchResults))
开发者ID:fzalkow,项目名称:music21,代码行数:6,代码来源:testCorpus.py


示例16: testSearch01

 def testSearch01(self):
     searchResults = corpus.search("china", field="locale")
     self.assertEqual(len(searchResults) > 1200, True)
开发者ID:fzalkow,项目名称:music21,代码行数:3,代码来源:testCorpus.py


示例17: testSearch07

 def testSearch07(self):
     searchResults = corpus.search("canon")
     self.assertEqual(len(searchResults) >= 1, True)
开发者ID:fzalkow,项目名称:music21,代码行数:3,代码来源:testCorpus.py


示例18: testSearch09

 def testSearch09(self):
     searchResults = corpus.search("3/.", field="timeSignature")
     self.assertEqual(len(searchResults) >= 2200, True)
开发者ID:fzalkow,项目名称:music21,代码行数:3,代码来源:testCorpus.py


示例19: testSearch

    def testSearch(self):

        from music21 import corpus, key

        post = corpus.search('china', 'locale')
        self.assertEqual(len(post) > 1200, True)
        
        post = corpus.search('Sichuan', 'locale')
        self.assertEqual(len(post), 47)
        
        post = corpus.search('Taiwan', 'locale')
        self.assertEqual(len(post), 27)
        self.assertEqual(post[0][0][-8:], 'han2.abc') # file
        self.assertEqual(post[0][1], '209') # work number
        
        post = corpus.search('Sichuan|Taiwan', 'locale')
        self.assertEqual(len(post), 74)


        post = corpus.search('bach')
        self.assertEqual(len(post) > 120, True)

        post = corpus.search('haydn', 'composer')
        self.assertEqual(len(post), 0)
        post = corpus.search('haydn|beethoven', 'composer')
        self.assertEqual(len(post) >= 16, True)


        post = corpus.search('canon')
        self.assertEqual(len(post) >= 1, True)

        post = corpus.search('3/8', 'timeSignature')
        self.assertEqual(len(post) > 360, True)

        post = corpus.search('3/.', 'timeSignature')
        self.assertEqual(len(post) >= 2200 , True)


        ks = key.KeySignature(3, 'major')
        post = corpus.search(str(ks), 'keySignature')
        self.assertEqual(len(post) >= 32, True)

        post = corpus.search('sharps (.*), mode phry(.*)', 'keySignature')
        self.assertEqual(len(post) >= 9, True)

        # searching virtual entries
        post = corpus.search('coltrane', 'composer')
        self.assertEqual(len(post) > 0, True)
        # returns items in pairs: url and work number
        self.assertEqual(post[0][0], 'http://static.wikifonia.org/1164/musicxml.mxl')
开发者ID:bewest,项目名称:music21-bewest.clone,代码行数:50,代码来源:base.py


示例20: testSearch09

 def testSearch09(self):
     searchResults = corpus.search('3/.', field='timeSignature')
     self.assertEqual(len(searchResults) >= 2200 , True)
开发者ID:cuthbertLab,项目名称:music21,代码行数:3,代码来源:testCorpus.py



注:本文中的music21.corpus.search函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python realizer.figuredBassFromStream函数代码示例发布时间:2022-05-27
下一篇:
Python corpus.parseWork函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap