<commit_before>#!/usr/bin/env python
# CREATED:2015-02-04 16:39:00 by <NAME> <<EMAIL>>
'''mir_eval integration'''

from decorator import decorator
import numpydoc
import mir_eval

from . import ns

__all__ = ['beat', 'chord', 'onset', 'segment', 'tempo']


def validate_annotation(ann, namespace):
    '''Validate that the annotation has the correct namespace,
    and is well-formed.

    Parameters
    ----------
    ann : pyjams.Annotation
        The annotation object in question

    namespace : str
        The namespace pattern to match `ann` against

    Returns
    -------
    valid : bool
        True if `ann` passes validation

    Raises
    ------
    RuntimeError
        If `ann` does not match the proper namespace

    jsonschema.ValidationError
        If `ann` fails schema validation
    '''

    if not ann.search(namespace=namespace):
        raise RuntimeError('Incorrect namespace in annotation. '
                           'Expected "{:s}", found "{:s}"'
                           .format(namespace, ann.namespace))

    ns.validate_annotation(ann, strict=True)

    return True


def jamsify_docstring(function, function_name, namespace):
    '''Modify the docstring for an existing function.

    This changes the documented call signature, parameters,
    and example strings for the function in question.

    Parameters
    ----------
    function : callable
        The function from which to get the original docstring<commit_msg>revised eval validator to reflect refactor<commit_after>#!/usr/bin/env python
# CREATED:2015-02-04 16:39:00 by <NAME> <<EMAIL>>
'''mir_eval integration'''

from decorator import decorator
import numpydoc
import mir_eval

from . import ns

__all__ = ['beat', 'chord', 'onset', 'segment', 'tempo']


def validate_annotation(ann, namespace):
    '''Validate that the annotation has the correct namespace,
    and is well-formed.

    Parameters
    ----------
    ann : pyjams.Annotation
        The annotation object in question

    namespace : str
        The namespace pattern to match `ann` against

    Returns
    -------
    valid : bool
        True if `ann` passes validation

    Raises
    ------
    RuntimeError
        If `ann` does not match the proper namespace

    jsonschema.ValidationError
        If `ann` fails schema validation
    '''

    if not ann.search(namespace=namespace):
        raise RuntimeError('Incorrect namespace in annotation. '
                           'Expected "{:s}", found "{:s}"'
                           .format(namespace, ann.namespace))

    ann.validate(strict=True)

    return True


def jamsify_docstring(function, function_name, namespace):
    '''Modify the docstring for an existing function.

    This changes the documented call signature, parameters,
    and example strings for the function in question.

    Parameters
    ----------
    function : callable
        The function from which to get the original docstring
{'fraction_non_alphanumeric': 0.10067796610169491, 'fraction_numerical': 0.009491525423728813, 'mean_word_length': 2.5089179548156957, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3456423', 'n_tokens_mistral': 805, 'n_tokens_neox': 750, 'n_words': 277}