Ejemplo n.º 1
0
    def get_symbtr_data(txt_file, mu2_file):
        extractor = DataExtractor()
        txt_data = extractor.extract(txt_file)[0]

        mu2_header = Mu2Reader.read_header(mu2_file)[0]

        return extractor.merge(txt_data, mu2_header, verbose=False)
    def sectionextractor(self):
        extractor = DataExtractor(extract_all_labels=True,
                                  print_warnings=False)
        data, is_data_valid = extractor.extract(self.txtpath,
                                                symbtr_name=self.symbtrname)

        mu2_header, header_row, is_header_valid = \
            Mu2Reader.read_header(self.mu2path, symbtr_name=self.symbtrname)

        # data = extractor.merge(txtdata, Mu2header)
        for item in data['sections']:
            self.sectionsextracted[item['start_note']] = item['name']

        mu2title = mu2_header['title']['mu2_title']
        if mu2title is None:
            mu2title = (mu2_header['makam']['mu2_name'] +
                        mu2_header['usul']['mu2_name'])

        mu2composer = mu2_header['composer']['mu2_name']
        mu2lyricist = mu2_header['lyricist']['mu2_name']
        mu2beatnumber = mu2_header['usul']['number_of_pulses']
        mu2beattype = mu2_header['usul']['mertebe']

        return (mu2_header, mu2composer, mu2lyricist, mu2beatnumber,
                mu2beattype, mu2title)
Ejemplo n.º 3
0
    def get_symbtr_data(txt_file, mu2_file):
        extractor = DataExtractor()
        txt_data = extractor.extract(txt_file)[0]

        mu2_header = Mu2Reader.read_header(mu2_file)[0]

        return extractor.merge(txt_data, mu2_header, verbose=False)
Ejemplo n.º 4
0
def test_txt_data():
    extractor = DataExtractor(print_warnings=False)
    [txtfilepaths, txtfolders, txtnames] = get_txt_filenames()

    is_all_txt_data_valid = True
    for tf, tn in zip(txtfilepaths, txtnames):
        try:
            txtdata, is_txt_data_valid = extractor.extract(tf)
            is_all_txt_data_valid = is_txt_data_valid \
                if is_all_txt_data_valid else False
        except (RuntimeError, ValueError, KeyError, TypeError):
            print "Unspecified error in " + tn
            is_all_txt_data_valid = False

    assert is_all_txt_data_valid
def test_with_full_input():
    """
    Tests the result with complete information available, i.e. mbid, phrase
    annotation and user provided segmentation
    """
    # inputs
    scorename = 'kurdilihicazkar--sarki--agiraksak--ehl-i_askin--tatyos_efendi'

    txt_filename = os.path.join(_curr_folder, 'data', scorename + '.txt')

    mbid = 'b43fd61e-522c-4af4-821d-db85722bf48c'

    auto_seg_file = os.path.join(_curr_folder, 'data', scorename + '.autoSeg')
    auto_seg_bounds = json.load(open(auto_seg_file, 'r'))['boundary_noteIdx']

    mu2_filename = os.path.join(_curr_folder, 'data', scorename + '.mu2')

    # initialize the extractor
    extractor = DataExtractor(extract_all_labels=False,
                              melody_sim_thres=0.75,
                              lyrics_sim_thres=0.75,
                              save_structure_sim=True,
                              get_recording_rels=False,
                              print_warnings=True)

    # extract txt_data
    txt_data, is_data_valid = extractor.extract(
        txt_filename,
        symbtr_name=scorename,
        mbid=mbid,
        segment_note_bound_idx=auto_seg_bounds)

    # extract mu2 header metadata
    mu2_header, header_row, is_header_valid = Mu2Reader.read_header(
        mu2_filename, symbtr_name=scorename)

    # merge
    data = DataExtractor.merge(txt_data, mu2_header)
    is_valid = is_data_valid and is_header_valid

    # compare with a previously saved result
    score_data_file = os.path.join(_curr_folder, 'data', scorename + '.json')
    saved_data = json.load(open(score_data_file))

    assert saved_data == data, u"{0:s}: the result is different".format(
        scorename)
    assert is_valid, "The data is not valid (or the validations failed.)"
def test_with_full_input():
    """
    Tests the result with complete information available, i.e. mbid, phrase
    annotation and user provided segmentation
    """
    # inputs
    scorename = 'kurdilihicazkar--sarki--agiraksak--ehl-i_askin--tatyos_efendi'

    txt_filename = os.path.join(_curr_folder, 'data', scorename + '.txt')

    mbid = 'b43fd61e-522c-4af4-821d-db85722bf48c'

    auto_seg_file = os.path.join(_curr_folder, 'data', scorename + '.autoSeg')
    auto_seg_bounds = json.load(open(auto_seg_file, 'r'))['boundary_noteIdx']

    mu2_filename = os.path.join(_curr_folder, 'data', scorename + '.mu2')

    # initialize the extractor
    extractor = DataExtractor(
        extract_all_labels=False, melody_sim_thres=0.75, lyrics_sim_thres=0.75,
        save_structure_sim=True, get_recording_rels=False, print_warnings=True)

    # extract txt_data
    txt_data, is_data_valid = extractor.extract(
        txt_filename, symbtr_name=scorename, mbid=mbid,
        segment_note_bound_idx=auto_seg_bounds)

    # extract mu2 header metadata
    mu2_header, header_row, is_header_valid = Mu2Reader.read_header(
        mu2_filename, symbtr_name=scorename)

    # merge
    data = DataExtractor.merge(txt_data, mu2_header)
    is_valid = is_data_valid and is_header_valid

    # compare with a previously saved result
    score_data_file = os.path.join(_curr_folder, 'data', scorename + '.json')
    saved_data = json.load(open(score_data_file))

    assert saved_data == data, u"{0:s}: the result is different".format(
        scorename)
    assert is_valid, "The data is not valid (or the validations failed.)"
def _basic_txt_extractor(score_name, use_name=True):
    txt_filename = os.path.join(_curr_folder, 'data', score_name + '.txt')
    symbtr_name = score_name if use_name is True else None

    # initialize the extractor
    extractor = DataExtractor(
        extract_all_labels=False, melody_sim_thres=0.7, lyrics_sim_thres=0.7,
        save_structure_sim=True, get_recording_rels=False, print_warnings=True)

    # extract txt_data
    txt_data, is_data_valid = extractor.extract(txt_filename,
                                                symbtr_name=symbtr_name)

    # compare with a previously saved result
    score_data_file = os.path.join(_curr_folder, 'data', score_name + '.json')
    saved_data = json.load(open(score_data_file))

    assert saved_data == txt_data, u"{0:s}: the result is different".format(
        score_name)
    assert is_data_valid, "The data is not valid (or the validations failed.)"
def _basic_txt_extractor(score_name, use_name=True):
    txt_filename = os.path.join(_curr_folder, 'data', score_name + '.txt')
    symbtr_name = score_name if use_name is True else None

    # initialize the extractor
    extractor = DataExtractor(extract_all_labels=False,
                              melody_sim_thres=0.7,
                              lyrics_sim_thres=0.7,
                              save_structure_sim=True,
                              get_recording_rels=False,
                              print_warnings=True)

    # extract txt_data
    txt_data, is_data_valid = extractor.extract(txt_filename,
                                                symbtr_name=symbtr_name)

    # compare with a previously saved result
    score_data_file = os.path.join(_curr_folder, 'data', score_name + '.json')
    saved_data = json.load(open(score_data_file))

    assert saved_data == txt_data, u"{0:s}: the result is different".format(
        score_name)
    assert is_data_valid, "The data is not valid (or the validations failed.)"