
    rhE                   D   S SK Jr  S SKJr  S SKJr  S SKrS SKrS SKrS SK	r	S SK
Jr  S SKJr  S SK
Jr  S SK
Jr  S S	K
Jr  S S
K
Jr  S SK
Jr  S SK
Jr  S SK
Jr  S SKJr  \R.                  " S5      r " S S\R2                  5      r " S S5      r " S S5      r " S S5      r " S S5      r " S S\R2                  5      r " S S5      r S r!S r"S(S  jr#S(S! jr$S(S" jr%S)S# jr& " S$ S%\	RN                  5      r(S& r)\ \\/r*\+S':X  a  S SK
r
\
RX                  " \(5        gg)*    )annotations)Counter)KeysViewN)common)
StreamType)	converter)corpus)environment)exceptions21)note)stream)text)MetadataEntryzfeatures.basec                      \ rS rSrSrg)FeatureException%    N__name__
__module____qualname____firstlineno____static_attributes__r       O/home/james-whalen/.local/lib/python3.13/site-packages/music21/features/base.pyr   r   %       r   r   c                  0    \ rS rSrSrS rS rS rS rSr	g)	Feature)   a  
An object representation of a feature, capable of presentation in a variety of formats,
and returned from FeatureExtractor objects.

Feature objects are simple. It is FeatureExtractors that store all metadata and processing
routines for creating Feature objects.  Normally you wouldn't create one of these yourself.

>>> myFeature = features.Feature()
>>> myFeature.dimensions = 3
>>> myFeature.name = 'Random arguments'
>>> myFeature.isSequential = True

This is a continuous Feature, so we will set discrete to false.

>>> myFeature.discrete = False

The .vector is the most important part of the feature, and it starts out as None.

>>> myFeature.vector is None
True

Calling .prepareVector() gives it a list of Zeros of the length of dimensions.

>>> myFeature.prepareVectors()

>>> myFeature.vector
[0, 0, 0]

Now we can set the vector parts:

>>> myFeature.vector[0] = 4
>>> myFeature.vector[1] = 2
>>> myFeature.vector[2] = 1

It's okay just to assign a new list to .vector itself.

There is a "normalize()" method which normalizes the values
of a histogram to sum to 1.

>>> myFeature.normalize()
>>> myFeature.vector
[0.571..., 0.285..., 0.142...]

And that's it! FeatureExtractors are much more interesting.
c                X    S U l         S U l        S U l        S U l        S U l        S U l        g N)
dimensionsvectornamedescriptionisSequentialdiscreteselfs    r   __init__Feature.__init__X   s0     	 r   c                "    S/U R                   -  $ )z1
Prepare a vector of appropriate size and return
r   )r"   r(   s    r   _getVectorsFeature._getVectorsd   s     sT__$$r   c                .    U R                  5       U l        g)z,
Prepare the vector stored in this feature.
N)r-   r#   r(   s    r   prepareVectorsFeature.prepareVectorsj   s     &&(r   c                    [        U R                  5      n SU-  nU R	                  5       n[        U R                  5       H  u  pEXR-  X4'   M     X0l        g! [         a    [        S5      ef = f)z=
Normalizes the vector so that the sum of its elements is 1.
      ?zcannot normalize zero vectorN)sumr#   ZeroDivisionErrorr   r-   	enumerate)r)   sscalartempivs         r   	normalizeFeature.normalizep   ss     	C1WF !dkk*DAjDG + ! 	C"#ABB	Cs   A A-)r%   r"   r'   r&   r$   r#   N)
r   r   r   r   __doc__r*   r-   r0   r<   r   r   r   r   r   r   )   s    ,\
%)r   r   c                  \    \ rS rSrSr S SS jjrS rS rSS jrS r	S	 r
SS
 jrS rSrg)FeatureExtractor   a  
A model of process that extracts a feature from a Music21 Stream.
The main public interface is the extract() method.

The extractor can be passed a Stream or a reference to a DataInstance.
All Streams are internally converted to a DataInstance if necessary.
Usage of a DataInstance offers significant performance advantages, as common forms of
the Stream are cached for easy processing.
Nc                r   S U l         S U l        U R                  U5        S U l        [	        U S5      (       d  S U l        [	        U S5      (       d  S U l        [	        U S5      (       d  S U l        [	        U S5      (       d  S U l        [	        U S5      (       d  SU l	        [	        U S5      (       d  SU l
        g g )	Nr$   r%   r&   r"   r'   Tr<   F)r   datasetDatafeaturehasattrr$   r%   r&   r"   r'   r<   )r)   dataOrStreamkeywordss      r   r*   FeatureExtractor.__init__   s     '+	\"tV$$DIt]++#Dt^,, $Dt\**"DOtZ(( DMt[))"DN *r   c                    Ub_  [        US5      (       a@  [        U[        R                  5      (       a!  Xl        [	        U R                  5      U l        gSU l        Xl        gg)zq
Set the data that this FeatureExtractor will process.
Either a Stream or a DataInstance object can be provided.
Nclasses)rF   
isinstancer   StreamDataInstancerC   )r)   rG   s     r   rD   FeatureExtractor.setData   sR    
 #i00"<??
 +(5	 #(	 $r   c                   / nU R                   S:X  a-  UR                  U R                  R                  SS5      5        U$ [	        U R                   5       H3  nUR                  U R                  R                  SS5       SU 35        M5     U$ )ai  
Return a list of string in a form that is appropriate for data storage.

>>> fe = features.jSymbolic.AmountOfArpeggiationFeature()
>>> fe.getAttributeLabels()
['Amount_of_Arpeggiation']

>>> fe = features.jSymbolic.FifthsPitchHistogramFeature()
>>> fe.getAttributeLabels()
['Fifths_Pitch_Histogram_0', 'Fifths_Pitch_Histogram_1', 'Fifths_Pitch_Histogram_2',
 'Fifths_Pitch_Histogram_3', 'Fifths_Pitch_Histogram_4', 'Fifths_Pitch_Histogram_5',
 'Fifths_Pitch_Histogram_6', 'Fifths_Pitch_Histogram_7', 'Fifths_Pitch_Histogram_8',
 'Fifths_Pitch_Histogram_9', 'Fifths_Pitch_Histogram_10', 'Fifths_Pitch_Histogram_11']

    _)r"   appendr$   replacerange)r)   postr:   s      r   getAttributeLabels#FeatureExtractor.getAttributeLabels   s|      ??aKK		))#s34  4??+tyy00c:;1QC@A ,r   c                    Uc  U R                   nU R                  Ul        U R                  Ul        U R                  Ul        U R                  Ul        U R
                  Ul        U$ )zP
Fill the attributes of a Feature with the descriptors in the FeatureExtractor.
)rE   r$   r%   r&   r"   r'   )r)   rE   s     r   fillFeatureAttributes&FeatureExtractor.fillFeatureAttributes   sV     ?llGyy"..#00!__==r   c                v    [        5       U l        U R                  5         U R                  R                  5         g)a  
Prepare a new Feature object for data acquisition.

>>> s = stream.Stream()
>>> fe = features.jSymbolic.InitialTimeSignatureFeature(s)
>>> fe.prepareFeature()
>>> fe.feature.name
'Initial Time Signature'
>>> fe.feature.dimensions
2
>>> fe.feature.vector
[0, 0]
N)r   rE   r[   r0   r(   s    r   prepareFeatureFeatureExtractor.prepareFeature   s)     y""$##%r   c                    g)z6
Do processing necessary, storing result in _feature.
Nr   r(   s    r   processFeatureExtractor.process   s    
 	r   c                    Ub  Xl         U R                  5         U R                  5         U R                  (       a  U R                  R                  5         U R                  $ )z,
Extract the feature and return the result.
)r   r^   ra   r<   rE   )r)   sources     r   extractFeatureExtractor.extract   sE      K>>LL""$||r   c                \    [        5       nU R                  U5        UR                  5         U$ )a  
Return a properly configured plain feature as a placeholder

>>> fe = features.jSymbolic.InitialTimeSignatureFeature()
>>> fe.name
'Initial Time Signature'

>>> blankF = fe.getBlankFeature()
>>> blankF.vector
[0, 0]
>>> blankF.name
'Initial Time Signature'
)r   r[   r0   )r)   fs     r   getBlankFeature FeatureExtractor.getBlankFeature  s*     I""1%	r   )	rC   r%   r"   r'   rE   r&   r$   r<   r   r!   )returnNone)r   r   r   r   r>   r*   rD   rX   r[   r^   ra   re   ri   r   r   r   r   r@   r@      s>     ## #.)&0&$r   r@   c                  ,   \ rS rSrSrS1S2S jjrS3S jrS4S jrS5S jrS6S7S jjr	S8S jr
S	 rS
 rS rS rS rS rS rS rS rS rS rS r0 SS _SS _SS _S\_SS _S\_S\
_S \_S!\_S"\_S#\_S$\_S%\_S&\_S'\_S(S) _S*S+ _S, \S- \S..ErS/rg0)9StreamFormsi  az  
A dictionary-like wrapper of a Stream, providing
numerous representations, generated on-demand, and cached.

A single StreamForms object can be created for an
entire Score, as well as one for each Part and/or Voice.

A DataSet object manages one or more StreamForms
objects, and exposes them to FeatureExtractors for usage.

The streamObj is stored as self.stream and if "prepared" then
the prepared form is stored as .prepared

A dictionary `.forms` stores various intermediary representations
of the stream which is the main power of this routine, making
it simple to add additional feature extractors at low additional
time cost.
c                    Xl         U R                   b:  U(       a!  U R                  U R                   5      U l        OU R                   U l        OS U l        0 U l        g r!   )r   _prepareStreampreparedforms)r)   	streamObjprepareStreams      r   r*   StreamForms.__init__)  sE    ;;" $ 3 3DKK @ $ DM 02
r   c                6    U R                   R                  5       $ r!   )rr   keysr(   s    r   rw   StreamForms.keys6  s    zz  r   c                $    UR                  SS9nU$ )zg
Common routines done on Streams prior to processing. Returns a new Stream

Currently: runs stripTies.
F)inPlace)	stripTies)r)   rs   s     r   rp   StreamForms._prepareStream:  s     '''6	r   c                l   XR                   ;   a  U R                   U   $ UR                  S5      nU R                  n[        [	        U5      5       H  nSR                  USUS-    5      nXPR                   ;   a  M+  US:  a#  SR                  USU 5      nU R                   U   nX$   nXpR                  ;   a  U R                  U   " X5      nOUUR                  S5      (       a.  U[	        S5      S nUR                  U5      R                  5       nO[        SU SU 35      eX0R                   U'   M     U$ )	zA
Get a form of this Stream, using a cached version if available.
.NrQ   r   zgetElementsByClass(zno such attribute: z in )rr   splitrq   rV   lenjoinkeysToMethods
startswithgetElementsByClassr   AttributeError)	r)   key	splitKeysrq   r:   subKeypreviousKeylastKey
classToGets	            r   __getitem__StreamForms.__getitem__D  s%   
 **::c?"IIcN	==s9~&AXXiQ/0F#1u!hhy!}5::k2lG,,,--g6tF##$9::")#.C*DR"H
#66zBIIK$':7)4u%MNN!)JJv% '( r   c                   S/S-  n[        U R                  [        R                  5      (       a   [	        U R                  R
                  5      nOU R                  /nU H  nUR                  SSSSS9n[        U5       Hg  u  pgU[        U5      S-
  :  d  M  US-   nXX   n	[        UR                  U5      n
[        U	R                  U5      n U[        X-
  5      ==   S-  ss'   Mi     M     U$ ! [         a     M~  f = f)Nr   rA   T	skipRests
skipChordsskipGapsnoNonerQ   )rL   rq   r   ScorelistpartsfindConsecutiveNotesr6   r   getattrpitchabsr   )r)   	algorithmhistor   prW   r:   niNextnNextnValue	nextValues               r   _getIntervalHistogram!StreamForms._getIntervalHistograme  s    c	 dmmV\\22,,-E]]OEA ))D593715 * 7D
 "$s4y1}$EE KE$QWWi8F 'Y ?Ic&"456!;6 ( (  * s   C00
C>=C>c                0    SSK Jn  UR                  U5      $ )Nr   )
instrument)music21r   partitionByInstrument)r)   rq   r   s      r   formPartitionByInstrument%StreamForms.formPartitionByInstrument  s    &//99r   c                V    [        U Vs/ s H  o"R                  PM     sn5      $ s  snf r!   )r   forteClassTnIr)   rq   cs      r   formSetClassHistogram!StreamForms.formSetClassHistogram  s!    :A:;;:   &c                V    [        U Vs/ s H  o"R                  PM     sn5      $ s  snf r!   )r   orderedPitchClassesStringr   s      r   formPitchClassSetHistogram&StreamForms.formPitchClassSetHistogram  s#    XFX33XFGGFr   c                    0 n/ SQnU H8  nU H/  nXR;  a  SX%'   [        XE5      " 5       (       d  M#  X%==   S-  ss'   M1     M:     U$ )N)isTriad	isSeventhisMajorTriadisMinorTriadisIncompleteMajorTriadisIncompleteMinorTriadisDiminishedTriadisAugmentedTriadisDominantSeventhisDiminishedSeventhisHalfDiminishedSeventhr   rQ   )r   )r)   rq   r   rw   r   thisKeys         r   formTypesHistogramStreamForms.formTypesHistogram  sR    +
 A'%&EN1&((Na'N    r   c                d   [        U[        R                  5      (       aq  [        R                  " 5       nUR                   HJ  nUR                  [        R                  5       H$  nUR                  UR                  U5      U5        M&     ML     U$ UR                  [        R                  5      nU$ r!   )	rL   r   r   rM   r   r   MeasureinsertgetOffsetBySite)r)   rq   rW   r   ms        r   formGetElementsByClassMeasure)StreamForms.formGetElementsByClassMeasure  s    h--==?D^^--fnn=AKK 1 1! 4a8 > $  ..v~~>Dr   c                d    [        U[        R                  5      (       a  UR                  SSS9$ U$ )NTF)addPartIdAsGroupremoveRedundantPitches)rL   r   r   chordify)r)   rq   s     r   formChordifyStreamForms.formChordify  s;    h-- $$!%e % E E
 Or   c                j    [        U Vs/ s H  n[        UR                  5      PM     sn5      $ s  snf r!   )r   floatquarterLength)r)   rq   r   s      r   formQuarterLengthHistogram&StreamForms.formQuarterLengthHistogram  s(    A1aoo.ABBAs   0c                V    [        U Vs/ s H  o"R                  PM     sn5      $ s  snf r!   )r   midi)r)   pitchesr   s      r   formMidiPitchHistogram"StreamForms.formMidiPitchHistogram  s!    010110r   c                    [        U Vs/ s H  o"R                  PM     sn5      nS/S-  nU H	  nX5   XE'   M     U$ s  snf )Nr      )r   
pitchClass)r)   r   r   ccr   ks         r   formPitchClassHistogram#StreamForms.formPitchClassHistogram  sE    G4GqllG45bAuEH 	 5s   =c                $    U R                  S5      $ )Nr   )r   )r)   unuseds     r   formMidiIntervalHistogram%StreamForms.formMidiIntervalHistogram  s    ))&11r   c                N   / nUR                  5       (       a  UR                  nOU/nU H  nUR                  SSSSS9n[        U5       H  u  pgU[	        U5      S-
  :  d  M  US-   nXX   n	UR
                  (       a(  UR                  5       R                  S   R                  n
OUR                  R                  n
U	R
                  (       a(  U	R                  5       R                  S   R                  nOU	R                  R                  nUR                  X-
  5        M     M     U$ )NTFr   rQ   r   )hasPartLikeStreamsr   r   r6   r   isChordsortDiatonicAscendingr   r   r   rT   )r)   rq   cListr   r   rW   r:   r   r   r   pspsNexts               r   formContourListStreamForms.formContourList  s   &&((NNEJEA ))D5:3715 * 7D "$D	A&EE KEyy446>>rBGGWW\\}}!&!<!<!>!F!Fr!J!O!O!&!1!1LL- ( 0 r   c                    / nUR                   nU H8  n[        US   [        R                  5      (       d  M'  UR	                  U5        M:     U$ )Nelement)
secondsMaprL   r   NotRestrT   )r)   rq   rW   r   bundles        r   formSecondsMapStreamForms.formSecondsMap  sE    ((
 F&+T\\::F# ! r   c                    U Vs/ s H  o"S   PM	     nnU Vs/ s H  n[        SU-  5      PM     nnS/S-  nU H(  nUS:  d  US:  a  M  [        U5      nXW==   S-  ss'   M*     U$ s  snf s  snf )NdurationSecondsg      N@r      (   rQ   )roundint)r)   r   dsecondsListbpmList	histogramthisBPMhistogramIndexs           r   formBeatHistogramStreamForms.formBeatHistogram  s    5?@Z*+Z@,78Kq5?K8C#I	G|w} \N%*%	 
  A8s
   A)A.flatc                "    UR                  5       $ r!   )flattenr   r   s     r   <lambda>StreamForms.<lambda>  s
    !))+r   r   c                    UR                   $ r!   )r   r	  s     r   r
  r     s    QYYr   notesc                    UR                   $ r!   )r  r	  s     r   r
  r    s    177r   getElementsByClass(Measure)metronomeMarkBoundariesc                "    UR                  5       $ r!   )r  r	  s     r   r
  r    s    Q5N5N5Pr   r   r   setClassHistogrampitchClassHistogramtypesHistogramquarterLengthHistogrampitchClassSetHistogrammidiPitchHistogrammidiIntervalHistogramcontourListanalyzedKeyc                     UR                  SS9$ )Nr   )method)analyze)r   rh   s     r   r
  r    s    %)@r   tonalCertaintyc                "    UR                  5       $ r!   )r  )r   foundKeys     r   r
  r    s    83J3J3Lr   c                    UR                   $ r!   )metadatar	  s     r   r
  r    s    ajjr   c                .    [         R                  " U5      $ r!   )r   assembleLyricsr	  s     r   r
  r    s    T-@-@-Cr   )r"  r   assembledLyricsbeatHistogram)rr   rq   r   NT)rs   stream.Stream)rk   zKeysView[str])rs   r   rk   r   )r   strrk   r(  )r   )rk   z	list[int])rq   r(  )r   r   r   r   r>   r*   rw   rp   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   r   rn   rn     sW   $2!B@:<H$		C22!F	-. 	* 	&'D	
 	"#P 	L 	 !: 	2 	6 	, 	!"< 	!"< 	4 	 !: 	  	@!" 	L#$ 1$C*+Mr   rn   c                  J    \ rS rSrSrSS jrS rSS jrS rS r	S	 r
S
 rSrg)rN   i  z
A data instance for analysis. This object prepares a Stream
(by stripping ties, etc.) and stores
multiple commonly-used stream representations once, providing rapid processing.
Nc                   [        U[        R                  5      (       a  Xl        S U l        OS U l        Xl        Ub  X l        GO9U R                  by  [        U R                  S5      (       a^  U R                  R                  bG  U R                  R                  R                  b&  U R                  R                  R                  U l        OU R                  b7  [        U R                  S5      (       a  U R                  R                  U l        OoU R                  b[  [        U R                  S5      (       a%  [        U R                  R                  5      U l        O"[        U R                  5      U l        OSU l        S U l
        S U l        SU l        S U l        / U l        / U l        / U l        U R                  b  U R#                  5         g g )Nr"  
sourcePath r   )rL   r   rM   
streamPath_idrF   r"  titler,  r)  
classLabel_classValue
partsCountrr   formsByVoiceformsByPart)featureExtractorClassesForParallelRunningsetupPostStreamParse)r)   streamOrPathids      r   r*   DataInstance.__init__   sV   lFMM22&K"DODK*O >Hkk%$++z22++&&2++&&,,8{{++11DH[[$l)K)K{{--DH__(t55t99:t/DH 
 9;6;;"%%' #r   c                   [        U R                  5      U l        / U l        [	        U R                  S5      (       af  [        U R                  R                  5      U l        U R                  R                   H'  nU R                  R                  [        U5      5        M)     OSU l        U R                  [        R                      H'  nU R                  R                  [        U5      5        M)     g)z
Set up the StreamForms objects and other things that
need to be done after a Stream is passed in but before
feature extracting is run.

Run automatically at instantiation if a Stream is passed in.
r   r   N)
rn   r   rr   r5  rF   r   r   r3  rT   Voice)r)   r   r;   s      r   r7  !DataInstance.setupPostStreamParseN  s     !-
 4;;((!$++"3"34DO[[&&  ''A7 '  DOV\\*A##KN3 +r   c                    Xl         X l        g)a-  
Set the class label, as well as the class value if known.
The class label is the attribute name used to define the class of this data instance.

>>> #_DOCS_SHOW s = corpus.parse('bwv66.6')
>>> s = stream.Stream() #_DOCS_HIDE
>>> di = features.DataInstance(s)
>>> di.setClassLabel('Composer', 'Bach')
N)r1  r2  )r)   r1  
classValues      r   setClassLabelDataInstance.setClassLabeli  s     %%r   c                   U R                   b'  [        U R                   5      (       a  U R                  c  g[        U R                   5      (       a-  U R                  b   U R                  U R                  5      U l         U R                   $ )Nr-  )r2  callabler   r(   s    r   getClassValueDataInstance.getClassValuev  sg    #x0@0@'A'AdkkFYD$$%%$++*A#//<Dr   c                   U R                   b'  [        U R                   5      (       a  U R                  c  g[        U R                   5      (       a-  U R                  b   U R                  U R                  5      U l          U R                   R                  SS5      $ ! [         a$  n[	        [        U R                   5      5      UeS nAff = f)Nr-  rR   rS   )r/  rC  r   rU   r   r)  )r)   es     r   getIdDataInstance.getId  s    88x11dkk6IDHH$++"9xx,DH	788##C-- 	7 TXX/Q6	7s   >B 
C$CCc                v   U R                   b  g[        U R                  [        5      (       a  [        R
                  R                  U R                  5      (       d   U R                  R                  S5      (       a"  [        R                  " U R                  5      nGO[        R                  " U R                  5      nO[        U R                  [        R                  5      (       aa  U R                  R                  5       (       a!  [        R                  " U R                  5      nO|[        R                  " U R                  5      nO[[        U R                  [        5      (       a  U R                  R                  5       nO![        S[        U R                  5       35      eXl         U R!                  5         g)z
If a path to a Stream has been passed in at creation,
then this will parse it (whether it's a corpus string,
a converter string (url or filepath), a pathlib.Path,
or a metadata.bundles.MetadataEntry).
NhttpzInvalid streamPath type: )r   rL   r.  r)  ospathexistsr   r   parser	   pathlibPathr   
ValueErrortyper7  )r)   r7   s     r   parseStreamDataInstance.parseStream  s    ;;"doos++ww~~doo..$//2L2LV2T2TOODOO4LL166%%''OODOO4LL177%%'A8doo9N8OPQQ!!#r   c                    U R                  5         US;   a  U R                  $ US;   a  U R                  $ U R                  U   $ )a-  
Get a form of this Stream, using a cached version if available.

>>> di = features.DataInstance('bach/bwv66.6')
>>> len(di['flat'])
197
>>> len(di['flat.pitches'])
163
>>> len(di['flat.notes'])
163
>>> len(di['getElementsByClass(Measure)'])
40
>>> len(di['flat.getElementsByClass(TimeSignature)'])
4
)r   )voices)rT  r5  r4  rr   )r)   r   s     r   r   DataInstance.__getitem__  sH      	)###J$$$ zz#r   )
r2  r/  r1  r6  rr   r5  r4  r3  r   r.  NNr!   )r   r   r   r   r>   r*   r7  r@  rD  rH  rT  r   r   r   r   r   rN   rN     s+    ,(\46& 7$<r   rN   c                      \ rS rSrSrg)DataSetExceptioni  r   Nr   r   r   r   r[  r[    r   r   r[  c                      \ rS rSrSrSS jrS rS r  SS jrSS jr	SS	 jr
SS
 jrSS jrS rS rS rSS jrS rS rS rSS jrSS jrSrg)DataSeti  a  
A set of features, as well as a collection of data to operate on.

Comprises multiple DataInstance objects, a FeatureSet, and an OutputFormat.


>>> ds = features.DataSet(classLabel='Composer')
>>> f = [features.jSymbolic.PitchClassDistributionFeature,
...      features.jSymbolic.ChangesOfMeterFeature,
...      features.jSymbolic.InitialTimeSignatureFeature]
>>> ds.addFeatureExtractors(f)
>>> ds.addData('bwv66.6', classValue='Bach')
>>> ds.addData('bach/bwv324.xml', classValue='Bach')
>>> ds.process()
>>> ds.getFeaturesAsList()[0]
['bwv66.6', 0.196..., 0.0736..., 0.006..., 0.098..., 0.0368..., 0.177..., 0.0,
 0.085..., 0.134..., 0.018..., 0.171..., 0.0, 0, 4, 4, 'Bach']
>>> ds.getFeaturesAsList()[1]
['bach/bwv324.xml', 0.25, 0.0288..., 0.125, 0.0, 0.144..., 0.125, 0.0, 0.163..., 0.0, 0.134...,
0.0288..., 0.0, 0, 4, 4, 'Bach']

>>> ds = ds.getString()


By default, all exceptions are caught and printed if debug mode is on.

Set ds.failFast = True to not catch them.

Set ds.quiet = False to print them regardless of debug mode.
Nc                    / U l         / U l        / U l        Xl        / U l        SU l        SU l        SU l        U R                  U5        g )NFT)	dataInstances_featureExtractors_instantiatedFeatureExtractors_classLabelfeaturesfailFastquietrunParalleladdFeatureExtractors)r)   r1  featureExtractorss      r   r*   DataSet.__init__  sN     #%.0+%
!!"34r   c                    U R                   $ r!   )rb  r(   s    r   getClassLabelDataSet.getClassLabel  s    r   c                    [         R                  " U5      (       d  U/nU H>  nU R                  R                  U5        U R                  R                  U" 5       5        M@     g)zX
Add one or more FeatureExtractor objects, either as a list or as an individual object.
N)r   
isIterabler`  rT   ra  )r)   valuessubs      r   rg  DataSet.addFeatureExtractors  sP       ((XFC##**3///66su= r   c                   / nU(       a  UR                  S5        U R                   H  nX4R                  5       -  nM     U R                  b2  U(       a+  UR                  U R                  R	                  SS5      5        U$ )a  
Return a list of all attribute labels. Optionally add a class
label field and/or an id field.


>>> f = [features.jSymbolic.PitchClassDistributionFeature,
...      features.jSymbolic.ChangesOfMeterFeature]
>>> ds = features.DataSet(classLabel='Composer', featureExtractors=f)
>>> ds.getAttributeLabels(includeId=False)
['Pitch_Class_Distribution_0',
 'Pitch_Class_Distribution_1',
 ...
 ...
 'Pitch_Class_Distribution_11',
 'Changes_of_Meter',
 'Composer']

IdentifierrR   rS   )rT   ra  rX   rb  rU   r)   includeClassLabel	includeIdrW   fes        r   rX   DataSet.getAttributeLabels  sl    & KK%55B))++D 6',=KK((00c:;r   c                    / nU(       a  UR                  S5        U R                   H  nX4R                  /UR                  -  -  nM!     U R                  b  U(       a  UR                  S5        U$ )ac  
Return column labels for discrete status.

>>> f = [features.jSymbolic.PitchClassDistributionFeature,
...      features.jSymbolic.ChangesOfMeterFeature]
>>> ds = features.DataSet(classLabel='Composer', featureExtractors=f)
>>> ds.getDiscreteLabels()
[None, False, False, False, False, False, False, False, False, False,
 False, False, False, True, True]
NT)rT   ra  r'   r"   rb  rt  s        r   getDiscreteLabelsDataSet.getDiscreteLabels+  sa     KK55B[[MBMM11D 6 ',=KKr   c                    / nU(       a  UR                  S5        U R                   H  nUS/UR                  -  -  nM     U R                  b  UR                  S5        U$ )a{  
Return column labels for the presence of a class definition

>>> f = [features.jSymbolic.PitchClassDistributionFeature,
...      features.jSymbolic.ChangesOfMeterFeature]
>>> ds = features.DataSet(classLabel='Composer', featureExtractors=f)
>>> ds.getClassPositionLabels()
[None, False, False, False, False, False, False, False, False,
 False, False, False, False, False, True]
NFT)rT   ra  r"   rb  )r)   rv  rW   rw  s       r   getClassPositionLabelsDataSet.getClassPositionLabelsA  s\     KK55BUGbmm++D 6 'KKr   c                   [        U5      (       d#  [        U5      [        U5      :w  a  [        S5      eUb3  [        U5      (       d#  [        U5      [        U5      :w  a  [        S5      e[        U5      (       a&   [        R                  " U5        U/[        U5      -  n[        U5      (       a'   [        R                  " U5        U/[        U5      -  nOUc  S/[        U5      -  n[        [        U5      5       H!  nX   nX$   nX4   nU R                  XVU5        M#     g! [        R
                   a    [        S5      ef = f! [        R
                   a    [        S5      ef = f)aY  
add multiple data points at the same time.

Requires an iterable (including MetadataBundle) for dataList holding
types that can be passed to addData, and an equally sized list of dataValues
and an equally sized list of ids (or None)

classValues can also be a pickleable function that will be called on
each instance after parsing, as can ids.
zJIf classValues is not a function, it must have the same length as dataListNzJIf ids is not a function or None, it must have the same length as dataListzVclassValues if a function must be pickleable. Lambda and some other functions are not.zNids if a function must be pickleable. Lambda and some other functions are not.)rC  r   r[  pickledumpsPicklingErrorrV   addData)r)   dataListclassValuesidsr:   r   cvthisIds           r   addMultipleDataDataSet.addMultipleDataW  sf    %%MS%55"\^ ^O MSX-"\^ ^ K  U[)
 '-#h-7KC==US!
 %#h-'C[&3x=(Cs8}%AABVFLL'	 &# '' U& (T U UU '' U& (T U UUs   ;D# 1E # E E&c                "   U R                   c  [        S5      eSn[        U[        5      (       a  UnUR                  nUc  UR
                  nOUn[        XS9nUR                  U R                   U5        U R                  R                  U5        g)z
Add a Stream, DataInstance, MetadataEntry, or path (Posix or str)
to a corpus or local file to this data set.

The class value passed here is assumed to be the same as
the classLabel assigned at startup.
NzCcannot add data unless a class label for this DataSet has been set.)r9  )	rb  r[  rL   rN   r   r.  r@  r_  rT   )r)   dataOrStreamOrPathr?  r9  r7   dis         r   r  DataSet.addData  s     #"UW W (,77#B		AyMM #A08B
)):6!!"%r   c                d    U R                   (       a  U R                  5       $ U R                  5       $ )zo
Process all Data with all FeatureExtractors.
Processed data is stored internally as numerous Feature objects.
)rf  _processParallel_processNonParallelr(   s    r   ra   DataSet.process  s+    
 ((**++--r   c                   U R                    H  nU R                  Ul        M     U R                  (       + n[        R
                  " U R                    Vs/ s H  oU R                  4PM     sn[        USSS9n[        U6 u  pEpg[        R                  " U5      nU H>  nU R                  SL a  [        R                  U5        M)  [        R                  U5        M@     X@l        [        U R                   5       HM  u  p[        UR                   5      (       a	  Xi   Ul        [        UR"                  5      (       d  MD  Xy   Ul        MO     gs  snf )z%
Run a set of processes in parallel.
rQ   T)updateFunctionupdateMultiplyunpackIterableN)r_  r`  r6  re  r   rf  rd  _dataSetParallelSubprocesszipflattenListenvironLocal
printDebugwarnrc  r6   rC  r2  r/  )
r)   r  shouldUpdate
outputDatafeatureDataerrorsr  r  rG  r:   s
             r   r  DataSet._processParallel  s    $$B;?;R;RB8 %  ::~ ''tGYGY(ZGYdmm)<GY(Z+E:F:;:>	*
 14Z0@-[##F+AzzT!''*!!!$	 
 $t112EA''!,	 3 )[s   E
c                   / U l         U R                   Hf  n/ nU R                   H6  nUR                  U5         UR	                  5       nUR                  U5        M8     U R                   R                  U5        Mh     g! [
         as  nSU[        U5      /nU R                  SL a  [        R                  U5        O[        R                  U5        U R                  SL a  UeUR                  5       n SnANSnAff = f)z'
The traditional way: run non-parallel
failed feature extractor:TN)rc  r_  ra  rD   re   	Exceptionr)  re  r  r  r  rd  ri   rT   )r)   rC   rowrw  	fReturnedrG  fLists          r   r  DataSet._processNonParallel  s    
 &&DC99

4 5 "

I 

9%# :& MM  %+ ' ! 
58"c!fEEzzT)$//6$))%0}}, " 2 2 4I
5s   A??
C<	A)C77C<c                   / n[        U R                  5       H  u  pV/ nU R                  U   nU(       a  UR                  UR	                  5       5        U H5  n	U(       a  XyR
                  -  nM  UR                  U	R
                  5        M7     U(       a  UR                  UR                  5       5        UR                  U5        M     U(       d  U(       d  US   $ U$ )z\
Get processed data as a list of lists, merging any sub-lists
in multidimensional features.
r   )r6   rc  r_  rT   rH  r#   rD  )
r)   ru  rv  concatenateListsrW   r:   r  r;   r  rh   s
             r   getFeaturesAsListDataSet.getFeaturesAsList  s    
 .FAA##A&B$#MAHHQXX&	 
 !))+,KKN / !7NKr   c                    / nU R                    H+  nUR                  5       nX1;  d  M  UR                  U5        M-     U$ )z'
Return a list of unique class values.
)r_  rD  rT   )r)   rW   r  r;   s       r   getUniqueClassValuesDataSet.getUniqueClassValues  s>     $$B  "A}A % r   c                    SSK Jn  UR                  5       S;   a  UR                  U S9nU$ UR                  5       S;   a  UR	                  U S9nU$ UR                  5       S;   a  UR                  U S9nU$ g )Nr   outputFormats)taborange	taborangeN)dataSet)csvcomma)arff	attribute)music21.featuresr  lowerOutputTabOrange	OutputCSV
OutputARFF)r)   featureFormatr  outputFormats       r   _getOutputFormatDataSet._getOutputFormat  s    2 $HH(888FL    "&66(2242@L
 	   "&;;(33D3AL  r   c                    SnSU;   aG  U R                  UR                  S5      S   5      b#  U R                  UR                  S5      S   5      nU$ )ay  
Get an output format from a file path if possible, otherwise return None.

>>> ds = features.DataSet()
>>> ds._getOutputFormatFromFilePath('test.tab')
<music21.features.outputFormats.OutputTabOrange object at ...>
>>> ds._getOutputFormatFromFilePath('test.csv')
<music21.features.outputFormats.OutputCSV object at ...>
>>> ds._getOutputFormatFromFilePath('junk') is None
True
Nr~   r   )r  r   )r)   fpofs      r   _getOutputFormatFromFilePath$DataSet._getOutputFormatFromFilePath  sP     "9$$RXXc]2%67C**288C=+<=	r   c                D    U R                  U5      nUR                  5       $ )zC
Get a string representation of the data set in a specific format.
)r  	getString)r)   	outputFmtr  s      r   r  DataSet.getString,  s#    
 ,,Y7%%''r   c                    Uc  Ub  U R                  U5      nOU R                  U5      nUc  [        SU SU 3-   5      eUR                  XS9$ )z
Set the output format object.
z1no output format could be defined from file path z or format )r  ru  )r  r  r[  write)r)   r  formatru  r  s        r   r  DataSet.write5  so     >bn<<R@L008L"#V(*t;vh%?$@ A A !!R!MMr   )rb  r`  ra  r_  rd  rc  re  rf  )Nr   )TTr'  r!   rY  )TTT)r  )NNT)r   r   r   r   r>   r*   rk  rg  rX   rz  r}  r  r  ra   r  r  r  r  r  r  r  r  r   r   r   r   r]  r]    sf    >5& > 48%):,,-(b&4. >&:4	
&(Nr   r]  c                   / n/ nU R                    H=  nU" 5       nUR                  U 5         UR                  5       nUR	                  U5        M?     X#U R                  5       U R                  5       4$ ! [         aO  nUR	                  S[        U5      -   S-   [        U5      -   5        U(       a  UeUR                  5       n S nANS nAff = f)Nr  z: )	r6  rD   re   r  rT   r)  ri   rD  rH  )dataInstancerd  r  r  feClassrw  r  rG  s           r   r  r  D  s    
CF  IIY


< 	-

I 	

9 J  224l6H6H6JJJ  	-MM5B?$FQOP**,I	-s   A33
C=ACCc                   SSK JnJn  [        SS9n[	        UR
                  5      [	        UR
                  5      -   nUR                  U5        UR                  U 5        UR                  5         UR                  SSSS9nU$ )a6  
returns a list containing ALL currently implemented feature extractors

streamInput can be a Stream, DataInstance, or path to a corpus or local
file to this data set.

>>> s = converter.parse('tinynotation: 4/4 c4 d e2')
>>> f = features.allFeaturesAsList(s)
>>> f[2:5]
[[2], [2], [1.0]]
>>> len(f) > 85
True
r   	jSymbolicnativer-  r1  F)ru  rv  r  )
r  r  r  r]  r   rh  rg  r  ra   r  )streamInputr  r  dsrh   allDatas         r   allFeaturesAsListr  \  sx     3	B	BY(()D1I1I,JJAAJJ{JJL""U-249 # ;G Nr   c                   SSK Jn  SSK Jn  [        R                  " U5      (       d  U/n/ nU HK  nUR                  5       S;   a  XBR                  -  nM'  UR                  5       S;   d  M=  XCR                  -  nMM     [        R                  " U 5      (       d  U /n / nU  HV  nUR                  5       R                  5       nUR                  SS5        UR                  SS5        UR                  U5        MX     / nU(       d  U$ U HK  n	U	R                  R                  5       U;   d  US   R                  5       S	:X  d  M:  UR                  U	5        MM     U$ )
a  
Given one or more :class:`~music21.features.FeatureExtractor` ids, return the
appropriate  subclass. An optional `library` argument can be added to define which
module is used. Current options are jSymbolic and native.

>>> features.extractorsById('p20')
[<class 'music21.features.jSymbolic.PitchClassDistributionFeature'>]

>>> [x.id for x in features.extractorsById('p20')]
['P20']
>>> [x.id for x in features.extractorsById(['p19', 'p20'])]
['P19', 'P20']


Normalizes case:

>>> [x.id for x in features.extractorsById(['r31', 'r32', 'r33', 'r34', 'r35', 'p1', 'p2'])]
['R31', 'R32', 'R33', 'R34', 'R35', 'P1', 'P2']

Get all feature extractors from all libraries:

>>> y = [x.id for x in features.extractorsById('all')]
>>> y[0:3], y[-3:-1]
(['M1', 'M2', 'M3'], ['CS12', 'MC1'])

r   )r  )r  )	jsymbolicall)r  r  -r-  rR   r  )r  r  r  r   rn  r  rh  striprU   rT   r9  )
idOrListlibraryr  r  rh  libflatIds	featureIdrW   rw  s
             r   extractorsByIdr  y  s)   6 +'W%%)99;..!<!<<YY[--!9!99	  X&&:G	OO%++-	#r"#r"y!	  D55;;=G#wqz'7'7'9U'BKKO   Kr   c                .    [        XS9nU(       a  US   $ g)z
Get the first feature matched by extractorsById().

>>> s = stream.Stream()
>>> s.append(note.Note('A4'))
>>> fe = features.extractorById('p20')(s)  # call class
>>> fe.extract().vector
[1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

)r  r  r   N)r  )r  r  ebis      r   extractorByIdr    s     (
<C
1vr   c                `    [        X5      " U 5      nUc  gUR                  5       R                  $ )z
Utility function to get a vector from an extractor

>>> s = stream.Stream()
>>> s.append(note.Note('A4'))
>>> features.vectorById(s, 'p20')
[1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
N)r  re   r#   )rs   vectorIdr  rw  s       r   
vectorByIdr    s-     
x	))	4B	z::<r   c                   SSK JnJn  Ub  US:X  a5  SnUR                   H#  nU" 5       R                  U :X  a  US4s  $ US-  nM%     Ub  US:X  a6  SnUR                   H#  nU" 5       R                  U :X  a  US4s  $ US-  nM%     gg)a  
Returns the list index of the given feature extractor and the feature extractor
category (jsymbolic or native). If feature extractor string is not in either
jsymbolic or native feature extractors, returns None

optionally include the extractorType ('jsymbolic' or 'native') if known
and searching will be made more efficient


>>> features.getIndex('Range')
(61, 'jsymbolic')
>>> features.getIndex('Ends With Landini Melodic Contour')
(18, 'native')
>>> features.getIndex('aBrandNewFeature!') is None
True
>>> features.getIndex('Fifths Pitch Histogram', 'jsymbolic')
(70, 'jsymbolic')
>>> features.getIndex('Tonal Certainty', 'native')
(1, 'native')
r   r  Nr  rQ   r  )r  r  r  rh  r$   )featureStringextractorTyper  r  
indexCountrE   s         r   getIndexr    s    * 3 <
 22Gy~~."K00!OJ	 3
  9
//Gy~~."H--!OJ 0
  !:r   c                  P    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rSrg)Testi  c                   SSK Jn  S U l        [        R                  " S5      nUR                  U5      nU R                  [        US   5      S5        U R                  [        US   5      S5        U R                  [        US   5      S	5        US
   nU R                  [        U5      S5        US   nU R                  USSSSSSSSSSSSSS.5        U R                  US   SSSSSSSSSSSS.5        U R                  US   SSS	SSSSSS .5        U R                  [        US!   5      S5        U R                  [        US!   S   S   5      S"5        U R                  [        US!   S#   S   5      S$5        U R                  [        US!   S   S%   5      S&5        U R                  [        US!   S#   S%   5      S&5        U R                  US!   S   S'   / S(Q5        U R                  US'   / S)Q5        g )*Nr   rc  corelli/opus3no1/1graver  i$  z
flat.notes   r      z'chordify.flat.getElementsByClass(Chord)   z9chordify.flat.getElementsByClass(Chord).setClassHistogram            r               )z3-11z2-4z1-1z2-3z3-9z2-2z3-7z2-5z3-4z3-6z3-10z3-8z3-2z6chordify.flat.getElementsByClass(Chord).typesHistogram"      )r   r   r   r   r   r   r   r   r   r   r   z!flat.notes.quarterLengthHistogramt   '         )g      ?r3   g      ?g       @g      @g      @g      ?g      ?r   G   rQ   B   r     zpitches.pitchClassHistogram)	   rQ      r   r     r   r  r   r   r   r   )/   r  r  r   r  *   r   !   r   &      r  )r   rc  maxDiffr	   rO  rN   assertEqualr   )r)   rc  r7   r  chordifiedChordsr   s         r   testStreamFormsATest.testStreamFormsA   s*   $LL23""1%RZ#.R-.4 	R
^,b1GH-.4NO 	"$R2bYZ!"1Qq!!"1.	/
 	TU,-1')PQ34PR78"12b	R	S 	?@""2AA !-	.
 	R[)1-R[^L9:B?R[^L9:B? 	R[^,IJKRPR[^,IJKRPGQ(EFA	C 	9:D	Fr   c                    SSK Jn  [        R                  " 5       nS H(  nUR	                  [
        R                  " U5      5        M*     UR                  U5      nU R                  US   / SQ5        g )Nr   r  )	c4r  d-4d#4f#4a#4d#5a5r   zpitches.midiIntervalHistogram)r  rQ   rQ   rQ   rQ   rQ   rQ   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )	r   rc  r   rM   rT   r   NoterN   r  )r)   rc  r7   r   r  s        r   testStreamFormsBTest.testStreamFormsB2  s\    $MMOLAHHTYYq\" M""1%;<D	Er   c                   SSK Jn  SSKJn  [        R
                  " 5       nS H(  nUR                  [        R                  " U5      5        M*     UR                  U5      nU R                  U" US   5      SU" US   5      5        g )Nr   )pformatr  )r  r  r  r  r  r  r  r   zflat.secondsMapa4  [{'durationSeconds': 0.5,
  'element': <music21.note.Note C>,
  'endTimeSeconds': 0.5,
  'offsetSeconds': 0.0,
  'voiceIndex': None},
 {'durationSeconds': 0.5,
  'element': <music21.note.Note C>,
  'endTimeSeconds': 1.0,
  'offsetSeconds': 0.5,
  'voiceIndex': None},
 {'durationSeconds': 0.5,
  'element': <music21.note.Note D->,
  'endTimeSeconds': 1.5,
  'offsetSeconds': 1.0,
  'voiceIndex': None},
 {'durationSeconds': 0.5,
  'element': <music21.note.Note D#>,
  'endTimeSeconds': 2.0,
  'offsetSeconds': 1.5,
  'voiceIndex': None},
 {'durationSeconds': 0.5,
  'element': <music21.note.Note F#>,
  'endTimeSeconds': 2.5,
  'offsetSeconds': 2.0,
  'voiceIndex': None},
 {'durationSeconds': 0.5,
  'element': <music21.note.Note A#>,
  'endTimeSeconds': 3.0,
  'offsetSeconds': 2.5,
  'voiceIndex': None},
 {'durationSeconds': 0.5,
  'element': <music21.note.Note D#>,
  'endTimeSeconds': 3.5,
  'offsetSeconds': 3.0,
  'voiceIndex': None},
 {'durationSeconds': 0.5,
  'element': <music21.note.Note A>,
  'endTimeSeconds': 4.0,
  'offsetSeconds': 3.5,
  'voiceIndex': None}]r   )pprintr%  r   rc  r   rM   rT   r   r!  rN   r  )r)   r%  rc  r7   r   r  s         r   testStreamFormsCTest.testStreamFormsCB  ss    "$MMOFAHHTYYq\" G""1%$5!67 ':N #2l#34O'	6r   c                ^   SSK Jn  SSKJn  UR	                  / SQS5      nUR                  SS9nSUl        UR                  U5        UR                  S	S
S9  UR                  SSS9  UR                  5         UR                  U5      nUR                  SS9nU R                  US5        UR                  SSS9nU R                  US5        UR                  SS9nUR                  SS9n[        R                  SS9n	UR                  U	SS9  XxU	4 H  n
[         R"                  " U
5        M     g )Nr   r  r  ql1ql2ql4r  Composerr  Fbwv66.6Bachr?  r  Corelliz//)	lineBreakzIdentifier,Unique_Note_Quarter_Lengths,Most_Common_Note_Quarter_Length,Range_of_Note_Quarter_Lengths,Composer//bwv66.6,3,1.0,1.5,Bach//corelli/opus3no1/1grave,8,0.5,3.75,Corelli)r3  rv  zUnique_Note_Quarter_Lengths,Most_Common_Note_Quarter_Length,Range_of_Note_Quarter_Lengths,Composer//3,1.0,1.5,Bach//8,0.5,3.75,Corellir  r  r  z.arff)suffixr  )r  r  )r   rc  r  r  r  r]  rf  rg  r  ra   r  r  r  r  r  getTempFilerL  remove)r)   rc  r  rh  r  r  rW   fp1fp2fp3r  s              r   testDataSetOutputTest.testDataSetOutputt  s7   $2$334I8T 4
 12 	

9
0


,
C


 $$R(||d|+[	\ ||de|<Y	Z
 hheh$hheh$&&g&6
C'S/BIIbM "r   c                   SSK Jn  SSK Jn  / SQnUR                  US5      nUR	                  SS9nUR                  U5        [        R                  " 5       nUR                  UR                  S 5      5        UR                  USS	9  UR                  US
S	9  SUl        U R                  UR                  5         UR                  5         S S S 5        g ! , (       d  f       g = f)Nr   r  )base)p10p11p12p13r  r.  r  
Monteverdir1  HandelT)r   rc  r>  r  r]  rg  r   rM   rT   ElementWrapperr  rd  assertRaisesr   ra   )r)   rc  r>  rh  r  r7   s         r   testFeatureFailTest.testFeatureFail  s    $ 8$334E4?A 4
 12 MMO	$$T*+


1
.


1
* x889JJL :99s   :C
C"c                   SSK Jn  SSK Jn  SSKJnJn  [        SS9n[        UR                  5      [        UR                  5      -   n[        R                  " 5       n[        R                  " 5       n[        R                  " 5       n	[        R                  " 5       n
U	R                  U
5        UR                  U	5        UR!                  U5        UR!                  U5        UR#                  U5        UR$                   H8  nUR&                   H%  nUR)                  U5         UR+                  5         M'     M:     g ! UR,                  UR.                  R0                  4 a     MW  f = f)Nr   )analysisr  r  r-  r  )r   rJ  rc  r  r  r  r]  r   rh  r   rM   r   Partr   rT   r   r  rg  r_  ra  rD   re   r   r'   DiscreteAnalysisException)r)   rJ  rc  r  r  r  rh   
bareStream	bareScore
singlePartsingleMeasurerC   rw  s                r   testEmptyStreamCustomErrors Test.testEmptyStreamCustomErrors  s   $$6#,,-V5M5M0NN]]_
LLN	[[]
(-($


:


9
"$$D77

4 JJL 8 % !11 ))CCE s   "D;;&E%$E%c                   SSK Jn  / SQnUR                  US5      n[        R                  " S5      R	                  S5      SS n[        R                  " S	5      R	                  S
S9SS nUR                  SS9nUR                  U5        U H  nUR                  USS9  M     U H  nUR                  USS9  M     UR                  5         UR                  SS9  UR                  SS9  UR                  SS9  g)r
Demonstrating writing out data files for feature extraction. Here,
features are used from the jSymbolic library.
r   r  r31r32r33r34r35p1p2p3p4p5p6p7p8p9r?  r@  rA  rB  p14p15p16p19p20p21r  
monteverdiz.xmlN+   bachr  )numberOfPartsr   r.  r  rC  r1  r0  r  r4  r  r  )
r   rc  r  r	   searchr]  rg  r  ra   r  )r)   rc  rh  worksMonteverdi	worksBachr  ws          r   %x_testComposerClassificationJSymbolic*Test.x_testComposerClassificationJSymbolic  s    
 	%N
 %334E4?A !--5<<VDSbIMM&)00q0A"1E	 4
 12
 !AJJq\J2 !AJJqVJ,  	




r   c                   SSK Jn  UR                  / SQS5      n[        R                  " S5      n[        R                  " S5      n[        R                  " S5      n[        R                  " S5      nUR                  S	S
9nUR                  U5        US4US44 HE  u  pUR                   H0  n
SU	 SU
R                  R                   3nUR                  U
SUS9  M2     MG     US4US44 HE  u  pUR                   H0  n
SU	 SU
R                  R                   3nUR                  U
SUS9  M2     MG     UR                  5         UR                  SS9  UR                  SS9  UR                  SS9  g)rT  r   r  rU  r  essenFolksong/han1essenFolksong/han2essenFolksong/boehme10essenFolksong/boehme20Regionr  han1han2essenFolksong/r  Chinar?  r9  boehme10boehme20Mitteleuropar  )r  r  r  N)r   rc  r  r	   rO  r]  rg  scoresr"  numberr  ra   r  )r)   rc  rh  oChina1oChina2oMitteleuropa1oMitteleuropa2r  or$   rq  songIds               r   $x_testRegionClassificationJSymbolicA)Test.x_testRegionClassificationJSymbolicA  su   
 	%$33 5C EP	Q ,,34,,34&>?&>?2
 12 !&) &)+GAXX)$q1B1B0CD

1V
< + (4'46GAXX)$q1B1B0CD

1F
C 6 	


u%
u%
v&r   c                   SSK Jn  UR                  / SQS5      nUR                  SS9nUR	                  U5        [
        R                  " S5      n[
        R                  " S5      nUS	44 HE  u  pgUR                   H0  nS
U SUR                  R                   3n	UR                  USU	S9  M2     MG     US44 HE  u  pgUR                   H0  nS
U SUR                  R                   3n	UR                  USU	S9  M2     MG     UR                  5         UR                  S5        UR                  S5        UR                  S5        UR                  SS9nUR	                  U5        [
        R                  " S5      n
[
        R                  " S5      nU
S44 HE  u  pgUR                   H0  nS
U SUR                  R                   3n	UR                  USU	S9  M2     MG     US44 HE  u  pgUR                   H0  nS
U SUR                  R                   3n	UR                  USU	S9  M2     MG     UR                  5         UR                  S5        UR                  S5        UR                  S5        g)zr
Demonstrating writing out data files for feature extraction.
Here, features are used from the jSymbolic library.
r   r  rU  r  ry  r  ru  rw  rz  r|  r  r}  r~  r  r  z&/_scratch/chinaMitteleuropaSplit-a.tabz&/_scratch/chinaMitteleuropaSplit-a.csvz'/_scratch/chinaMitteleuropaSplit-a.arffrv  rx  r{  r  z&/_scratch/chinaMitteleuropaSplit-b.tabz&/_scratch/chinaMitteleuropaSplit-b.csvz'/_scratch/chinaMitteleuropaSplit-b.arffN)r   rc  r  r]  rg  r	   rO  r  r"  r  r  ra   r  )r)   rc  rh  r  r  r  r  r$   rq  r  r  r  s               r   $x_testRegionClassificationJSymbolicB)Test.x_testRegionClassificationJSymbolicB4  sV   
 	% %33GHSU 2
 12,,34&>? !&)*GAXX)$q1B1B0CD

1V
<  +
 (45GAXX)$q1B1B0CD

1F
C  6 	


9:
9:
:; 2
 12,,34&>? &)*GAXX)$q1B1B0CD

1V
<  +
 (45GAXX)$q1B1B0CD

1F
C  6 	


9:
9:
:;r   c                   SSK Jn  UR                  / SQS5      nUR                  SS9nUR	                  U5        UR                  SSS	9  UR                  S
SS	9  SUl        SUl        UR                  5         U R                  [        UR                  5      S5        U R                  [        UR                  S   5      S5        UR                  S   S   nU R                  UR                  S/5        g )Nr   r  r*  r  r.  r  r/  r0  r1  r  r2  Tr  r  )r   rc  r  r]  rg  r  rf  re  ra   r  r   r#   )r)   rc  rh  r  fe00s        r   testParallelRunTest.testParallelRun  s    $$334I8T 4
 12 	

9
0


,
C


R[[)1-R[[^,a0{{1~a qc*r   )r  N)r   r   r   r   r  r"  r'  r;  rG  rQ  rr  r  r  r  r   r   r   r   r  r    s=    0FdE 06d(T2\$ L''R:<d+r   r  c                ,    [        U R                  5      $ )z?
A function for documentation testing of a pickleable function
)r   r   )
bachStreams    r   _pickleFunctionNumPitchesr  C  s     z!!""r   __main__)r  r!   )-
__future__r   collectionsr   collections.abcr   rL  rP  r  unittestr   r   music21.common.typesr   r   r	   r
   r   r   r   r   music21.metadata.bundlesr   Environmentr  Music21Exceptionr   r   r@   rn   rN   r[  r]  r  r  r  r  r  r  TestCaser  r  
_DOC_ORDERr   mainTestr   r   r   <module>r     s   #  $ 	     +         2&&7	|44 	S SnR Rl~ ~Dk k^	|44 	vN vNrK0:9x"%RZ+8 Z+J# w 01
 zT r   