music21.search.lyrics¶
LyricSearcher¶
-
class
music21.search.lyrics.
LyricSearcher
(s=None)¶ An object that can find lyrics that match a certain regular expression and return relevant information about the match.
Currently searches the first lyric only.
LyricSearcher
methods
-
LyricSearcher.
index
(s=None)¶ >>> from pprint import pprint as pp
>>> p0 = corpus.parse('luca/gloria').parts[0] >>> ls = search.lyrics.LyricSearcher(p0) >>> pp(ls.index()[0:5]) [IndexedLyric(el=<music21.note.Note C>, start=0, end=2, measure=1, lyric=<music21.note.Lyric number=1 syllabic=single text="Et">, text=...'Et'), IndexedLyric(el=<music21.note.Note D>, start=3, end=5, measure=2, lyric=<music21.note.Lyric number=1 syllabic=single text="in">, text=...'in'), IndexedLyric(el=<music21.note.Note F>, start=6, end=9, measure=2, lyric=<music21.note.Lyric number=1 syllabic=begin text="ter">, text=...'ter'), IndexedLyric(el=<music21.note.Note F>, start=9, end=11, measure=3, lyric=<music21.note.Lyric number=1 syllabic=end text="ra">, text=...'ra'), IndexedLyric(el=<music21.note.Note A>, start=12, end=15, measure=3, lyric=<music21.note.Lyric number=1 syllabic=single text="pax">, text=...'pax')]
-
LyricSearcher.
search
(textOrRe, s=None)¶ >>> from pprint import pprint as pp >>> import re
>>> p0 = corpus.parse('luca/gloria').parts[0] >>> ls = search.lyrics.LyricSearcher(p0) >>> ls.search('pax') # ellipsis because of unicode in Py2 [SearchMatch(mStart=3, mEnd=3, matchText=...'pax', els=(<music21.note.Note A>,), tups=[IndexedLyric(...)])]
Search a regular expression that takes into account non-word characters such as commas
>>> agnus = re.compile('agnus dei\W+filius patris', re.IGNORECASE) >>> sm = ls.search(agnus) >>> sm [SearchMatch(mStart=49, mEnd=55, matchText=...'Agnus Dei, Filius Patris', els=(<music21.note.Note G>,...<music21.note.Note G>), tups=[IndexedLyric(el=<music21.note.Note G>, start=251, end=252, measure=49, lyric=<...>, text=...'A'), ... IndexedLyric(el=<music21.note.Note G>, ...text=...'tris.')])] >>> sm[0].mStart, sm[0].mEnd (49, 55)
IndexedLyric¶
-
class
music21.search.lyrics.
IndexedLyric
(el, start, end, measure, lyric, text)¶
IndexedLyric
read-only properties
-
IndexedLyric.
el
¶ Alias for field number 0
-
IndexedLyric.
end
¶ Alias for field number 2
-
IndexedLyric.
lyric
¶ Alias for field number 4
-
IndexedLyric.
measure
¶ Alias for field number 3
-
IndexedLyric.
start
¶ Alias for field number 1
-
IndexedLyric.
text
¶ Alias for field number 5
SearchMatch¶
-
class
music21.search.lyrics.
SearchMatch
(mStart, mEnd, matchText, els, tups)¶
SearchMatch
read-only properties
-
SearchMatch.
els
¶ Alias for field number 3
-
SearchMatch.
mEnd
¶ Alias for field number 1
-
SearchMatch.
mStart
¶ Alias for field number 0
-
SearchMatch.
matchText
¶ Alias for field number 2
-
SearchMatch.
tups
¶ Alias for field number 4