<commit_before>from .decorators import parser as _parser


def __parse_bool(string, errors=False):
    lower_string = str(string).lower()

    if lower_string == "true":
        return True
    elif lower_string == "false":
        return False
    else:
        if bool(errors):
            raise ValueError("could not convert string to bool: '%s'" % string)
        else:
            return string


parse_bool = _parser(__parse_bool)


def __parse_none(string, errors=False):
    lower_string = str(string).lower()

    if lower_string in ["", "#n/a", "null", "none", "undefined"]:
        return None
    else:
        if bool(errors):
            raise ValueError("could not convert string to None: '%s'" % string)
        else:
            return string


parse_none = _parser(__parse_none)


def __lazy_parse(string, errors=False):
    if "string" in string:
        if bool(errors):
            raise ValueError("could not parse string: '%s'" % string)
        else:
            return string
    else:
        try:
            return eval(string)
        except (NameError, SyntaxError):
            if bool(errors):
                raise ValueError("could not parse string: '%s'" % string)
            else:
                return string


lazy_parse = _parser(__lazy_parse)


@_parser
def parse(string, errors=False):
    try:
        return __parse_bool(string, errors=True)
    except ValueError:
        pass

    try:
        return __parse_none(string, errors=True)
    except ValueError:
        pass

    try:
        return __lazy_parse(string, errors=True)
    except ValueError:
        pass

    if bool(errors):
        raise ValueError("could not parse string: '%s'" % string)
    else:
        return string


def create_lazy_parser(arg):
    if callable(arg):
        return arg
    elif bool(arg):
        return lazy_parse
    else:
        return lambda string: string


def create_parser(arg):
    if callable(arg):
        return arg
    elif bool(arg):
        return parse
    else:
        return lambda string: string
<commit_msg>Removed duplicate code<commit_after>from .decorators import parser as _parser


def __parse_bool(string, errors=False):
    lower_string = str(string).lower()

    if lower_string == "true":
        return True
    elif lower_string == "false":
        return False
    else:
        if bool(errors):
            raise ValueError("could not convert string to bool: '%s'" % string)
        else:
            return string


parse_bool = _parser(__parse_bool)


def __parse_none(string, errors=False):
    lower_string = str(string).lower()

    if lower_string in ["", "#n/a", "null", "none", "undefined"]:
        return None
    else:
        if bool(errors):
            raise ValueError("could not convert string to None: '%s'" % string)
        else:
            return string


parse_none = _parser(__parse_none)


def __lazy_parse(string, errors=False):
    if "string" in string:
        if bool(errors):
            raise ValueError("could not parse string: '%s'" % string)
        else:
            return string
    else:
        try:
            return eval(string)
        except (NameError, SyntaxError):
            if bool(errors):
                raise ValueError("could not parse string: '%s'" % string)
            else:
                return string


lazy_parse = _parser(__lazy_parse)


@_parser
def parse(string, errors=False):
    try:
        return __parse_bool(string, errors=True)
    except ValueError:
        pass

    try:
        return __parse_none(string, errors=True)
    except ValueError:
        pass

    try:
        return __lazy_parse(string, errors=True)
    except ValueError:
        pass

    if bool(errors):
        raise ValueError("could not parse string: '%s'" % string)
    else:
        return string


def _create_parser(arg, default_parser):
    if callable(arg):
        return arg
    elif bool(arg):
        return default_parser
    else:
        return lambda string: string


def create_lazy_parser(arg):
    return _create_parser(arg, lazy_parse)


def create_parser(arg):
    return _create_parser(arg, parse)

{'fraction_non_alphanumeric': 0.09376510391493476, 'fraction_numerical': 0.0, 'mean_word_length': 2.2616233254531126, 'pattern_counts': {'":': 4, '<': 3, '<?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': '7024997', 'n_tokens_mistral': 1181, 'n_tokens_neox': 1163, 'n_words': 350}