c8867b6e46695ea5f7bd9ecfed44b35d42df38c4,mir_eval/io.py,,load_patterns,#,264

Before Change


             P = [[[(77.0, 67.0), (77.5, 77.0), ... ]]]
    

    with open(filename, "r") as input_file:
        // List with all the patterns
        pattern_list = []
        // Current pattern, which will contain all occs
        pattern = []
        // Current occurrence, containing (onset, midi)
        occurrence = []
        for line in input_file.readlines():
            if "pattern" in line:
                if occurrence != []:
                    pattern.append(occurrence)
                if pattern != []:
                    pattern_list.append(pattern)
                occurrence = []
                pattern = []
                continue
            if "occurrence" in line:
                if occurrence != []:
                    pattern.append(occurrence)
                occurrence = []
                continue
            string_values = line.split(",")
            onset_midi = (float(string_values[0]), float(string_values[1]))
            occurrence.append(onset_midi)

        // Add last occurrence and pattern to pattern_list
        if occurrence != []:
            pattern.append(occurrence)
        if pattern != []:
            pattern_list.append(pattern)

    return pattern_list


def load_wav(path, mono=True):

After Change


    // Keep track of whether we create our own file handle
    own_fh = False
    // If the filename input is a string, need to open it
    if type(filename) == str:
        // Remember that we need to close it later
        own_fh = True
        // Open the file for reading
        input_file = open(filename, "r")
    // If the provided has a read attribute, we can use it as a file handle
    elif hasattr(filename, "read"):
        input_file = filename
    // Raise error otherwise
    else:
        raise ValueError("filename must be a string or file handle")

    // List with all the patterns
    pattern_list = []
    // Current pattern, which will contain all occs
    pattern = []
    // Current occurrence, containing (onset, midi)
    occurrence = []
    for line in input_file.readlines():
        if "pattern" in line:
            if occurrence != []:
                pattern.append(occurrence)
            if pattern != []:
                pattern_list.append(pattern)
            occurrence = []
            pattern = []
            continue
        if "occurrence" in line:
            if occurrence != []:
                pattern.append(occurrence)
            occurrence = []
            continue
        string_values = line.split(",")
        onset_midi = (float(string_values[0]), float(string_values[1]))
        occurrence.append(onset_midi)

    // Add last occurrence and pattern to pattern_list
    if occurrence != []:
        pattern.append(occurrence)
    if pattern != []:
        pattern_list.append(pattern)

    // If we opened an input file, we need to close it
    if own_fh:
        input_file.close()

    return pattern_list

Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 12

Instances


Project Name: craffel/mir_eval
Commit Name: c8867b6e46695ea5f7bd9ecfed44b35d42df38c4
Time: 2014-10-28
Author: craffel@gmail.com
File Name: mir_eval/io.py
Class Name:
Method Name: load_patterns


Project Name: THUNLP-MT/THUMT
Commit Name: ea5fe95ffd6f31886c39219aac61c64b0cb8ba0b
Time: 2019-07-13
Author: cg847519328@163.com
File Name: thumt/bin/translator.py
Class Name:
Method Name: main


Project Name: craffel/mir_eval
Commit Name: 3e34690bca279c672505a58212746c8053595412
Time: 2014-10-28
Author: craffel@gmail.com
File Name: mir_eval/io.py
Class Name:
Method Name: load_delimited