<commit_before>from metadata import getAttributeDict
import copy 

def extractRhythmicStructure(score):
	usul_bounds = [ii for ii, code in enumerate(score['code']) if code == 51]

	rhythmic_structure = []
	for ii, ub in enumerate(usul_bounds):
		start = ub
		if ii < len(usul_bounds)-1:
			end = usul_bounds[ii+1]  
		else:  # end of file
			end = len(score['code'])

		usul = {'mu2_name':score['lyrics'][ii],'mertebe':score['denumerator'][ii],
				'number_of_pulses':score['numerator'][ii], 'symbtr_internal':score['lns'][ii]}

		# compute the tempo from the next note
		tempo = []
		it = ii+1
		while not tempo:
			if score['code'][it] == 9:  # proper note
				tempo = computeTempoFromNote(score['numerator'][it], score['denumerator'][it], 
					score['duration'][it],usul['mertebe'])
			else:
				it += 1

		rhythmic_structure.append({'usul':usul, 'tempo':tempo, 
			'start_note':start, 'end_note':end})

	return rhythmic_structure

def computeTempoFromNote(note_num, note_denum, note_dur, mertebe):
	sym_dur = float(note_num)/note_denum
	rel_dur_wrt_mertebe = mertebe * sym_dur * 0.001
	tempo = int(round(60.0 / (note_dur * rel_dur_wrt_mertebe)))
	
	return tempo<commit_msg>Fixed the indexing in usul extraction<commit_after>from metadata import getAttributeDict
import copy 

def extractRhythmicStructure(score):
	usul_bounds = [ii for ii, code in enumerate(score['code']) if code == 51]

	rhythmic_structure = []
	for ii, ub in enumerate(usul_bounds):
		start = score['index'][ub]
		if ii < len(usul_bounds)-1:
			end = score['index'][usul_bounds[ii+1]-1]
		else:  # end of file
			end = score['index'][len(score['code'])-1]

		usul = {'mu2_name':score['lyrics'][ub],'mertebe':score['denumerator'][ub],
				'number_of_pulses':score['numerator'][ub], 'symbtr_internal':score['lns'][ub]}

		# compute the tempo from the next note
		tempo = []
		it = ub+1
		while not tempo:
			if score['code'][it] == 9:  # proper note
				tempo = computeTempoFromNote(score['numerator'][it], score['denumerator'][it], 
					score['duration'][it],usul['mertebe'])
			else:
				it += 1

		rhythmic_structure.append({'usul':usul, 'tempo':{'value':tempo, 'unit':'bpm'}, 
			'startNote':start, 'endNote':end})

	return rhythmic_structure

def computeTempoFromNote(note_num, note_denum, note_dur, mertebe):
	sym_dur = float(note_num)/note_denum
	rel_dur_wrt_mertebe = mertebe * sym_dur * 0.001

	tempo = int(round(60.0 / (note_dur * rel_dur_wrt_mertebe)))
	
	return tempo
{'fraction_non_alphanumeric': 0.15776600081532818, 'fraction_numerical': 0.013045250713412148, 'mean_word_length': 5.228426395939087, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '751176', 'n_tokens_mistral': 1018, 'n_tokens_neox': 929, 'n_words': 183}