<commit_before>from .validator import validator

from ..helpers.parsing import tokenize, ContextualPair

from funcparserlib.parser import NoParseError

# from utils.logging import logger

def command(parser, *args, **kwargs):

    def validate_parser(content):
        try:
            tokens = tokenize(content)
            # logger.debug(tokens)
            parsed = parser.parse(tokens)
            if not type(parsed) is list:
                parsed = [parsed]
            # logger.debug(parsed)
            return True, dict([
                named for named in parsed
                if type(named) is ContextualPair
            ])
        except NoParseError as e:
            # logger.error(e)
            return False, {}

    return validator(validate_parser, *args, **kwargs)
<commit_msg>Fixed the contextualization of tokens<commit_after>from .validator import validator

from ..helpers.parsing import tokenize, ContextualPair

from funcparserlib.parser import NoParseError,_Tuple

# from utils.logging import logger

def command(parser, *args, **kwargs):

    def validate_parser(content):
        try:
            tokens = tokenize(content)
            # logger.debug(tokens)
            parsed = parser.parse(tokens)
            if type(parsed) is not _Tuple:
                parsed = [parsed]
            # logger.debug(parsed)
            return True, dict([
                named for named in parsed
                if type(named) is ContextualPair
            ])
        except NoParseError as e:
            # logger.error(e)
            return False, {}

    return validator(validate_parser, *args, **kwargs)

{'fraction_non_alphanumeric': 0.0815450643776824, 'fraction_numerical': 0.0, 'mean_word_length': 2.0504672897196263, 'pattern_counts': {'":': 0, '<': 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': '7375037', 'n_tokens_mistral': 420, 'n_tokens_neox': 426, 'n_words': 124}