msaf/input_output.py
def find_estimation(jam, boundaries_id, labels_id, params):
    """Finds the correct estimation from all the estimations contained in a
    JAMS file given the specified arguments.

    Parameters
    ----------
    jam : jams.JAMS
        JAMS object.
    boundaries_id : str
        Identifier of the algorithm used to compute the boundaries.
    labels_id : str
        Identifier of the algorithm used to compute the labels.
    params : dict
        Additional search parameters. E.g. {"feature" : "pcp"}.

    Returns
    -------
    ann : jams.Annotation
        Found estimation.
        `None` if it couldn't be found.
    """
    # Use handy JAMS search interface
    namespace = "multi_segment" if params["hier"] else "segment_open"
    # TODO: This is a workaround to issue in JAMS. Should be
    # resolved in JAMS 0.2.3, but for now, this works too.
    ann = jam.search(namespace=namespace).\
        search(**{"Sandbox.boundaries_id": boundaries_id}).\
        search(**{"Sandbox.labels_id": lambda x:
                  (isinstance(x, six.string_types) and
                   re.match(labels_id, x) is not None) or x is None})
    for key, val in zip(params.keys(), params.values()):
        if isinstance(val, six.string_types):
            ann = ann.search(**{"Sandbox.%s" % key: val})
        else:
            ann = ann.search(**{"Sandbox.%s" % key: lambda x: x == val})

    # Check estimations found
    if len(ann) > 1:
        logging.warning("More than one estimation with same parameters.")

    if len(ann) > 0:
        ann = ann[0]

    # If we couldn't find anything, let's return None
    if not ann:
        ann = None

    return ann
def find_estimation(jam, boundaries_id, labels_id, params):
    # Use handy JAMS search interface
    namespace = "multi_segment" if params["hier"] else "segment_open"
    # TODO: This is a workaround to issue in JAMS. Should be
    # resolved in JAMS 0.2.3, but for now, this works too.
    ann = jam.search(namespace=namespace).\
        search(**{"Sandbox.boundaries_id": boundaries_id}).\
        search(**{"Sandbox.labels_id": lambda x:
                  (isinstance(x, six.string_types) and
                   re.match(labels_id, x) is not None) or x is None})
    for key, val in zip(params.keys(), params.values()):
        if isinstance(val, six.string_types):
            ann = ann.search(**{"Sandbox.%s" % key: val})
        else:
            ann = ann.search(**{"Sandbox.%s" % key: lambda x: x == val})

    # Check estimations found
    if len(ann) > 1:
        logging.warning("More than one estimation with same parameters.")

    if len(ann) > 0:
        ann = ann[0]

    # If we couldn't find anything, let's return None
    if not ann:
        ann = None

    return ann
def find_estimation ( jam , boundaries_id , labels_id , params ) : # Use handy JAMS search interface namespace = "multi_segment" if params [ "hier" ] else "segment_open" # TODO: This is a workaround to issue in JAMS. Should be # resolved in JAMS 0.2.3, but for now, this works too. ann = jam . search ( namespace = namespace ) . search ( * * { "Sandbox.boundaries_id" : boundaries_id } ) . search ( * * { "Sandbox.labels_id" : lambda x : ( isinstance ( x , six . string_types ) and re . match ( labels_id , x ) is not None ) or x is None } ) for key , val in zip ( params . keys ( ) , params . values ( ) ) : if isinstance ( val , six . string_types ) : ann = ann . search ( * * { "Sandbox.%s" % key : val } ) else : ann = ann . search ( * * { "Sandbox.%s" % key : lambda x : x == val } ) # Check estimations found if len ( ann ) > 1 : logging . warning ( "More than one estimation with same parameters." ) if len ( ann ) > 0 : ann = ann [ 0 ] # If we couldn't find anything, let's return None if not ann : ann = None return ann
Finds the correct estimation from all the estimations contained in a
    JAMS file given the specified arguments.

    Parameters
    ----------
    jam : jams.JAMS
        JAMS object.
    boundaries_id : str
        Identifier of the algorithm used to compute the boundaries.
    labels_id : str
        Identifier of the algorithm used to compute the labels.
    params : dict
        Additional search parameters. E.g. {"feature" : "pcp"}.

    Returns
    -------
    ann : jams.Annotation
        Found estimation.
        `None` if it couldn't be found.
Finds the correct estimation from all the estimations contained in a JAMS file given the specified arguments .