

def tag_pattern2re_pattern(tag_pattern):
    '\n    Convert a tag pattern to a regular expression pattern.  A "tag\n    pattern" is a modified version of a regular expression, designed\n    for matching sequences of tags.  The differences between regular\n    expression patterns and tag patterns are:\n\n        - In tag patterns, ``\'<\'`` and ``\'>\'`` act as parentheses; so\n          ``\'<NN>+\'`` matches one or more repetitions of ``\'<NN>\'``, not\n          ``\'<NN\'`` followed by one or more repetitions of ``\'>\'``.\n        - Whitespace in tag patterns is ignored.  So\n          ``\'<DT> | <NN>\'`` is equivalant to ``\'<DT>|<NN>\'``\n        - In tag patterns, ``\'.\'`` is equivalant to ``\'[^{}<>]\'``; so\n          ``\'<NN.*>\'`` matches any single tag starting with ``\'NN\'``.\n\n    In particular, ``tag_pattern2re_pattern`` performs the following\n    transformations on the given pattern:\n\n        - Replace \'.\' with \'[^<>{}]\'\n        - Remove any whitespace\n        - Add extra parens around \'<\' and \'>\', to make \'<\' and \'>\' act\n          like parentheses.  E.g., so that in \'<NN>+\', the \'+\' has scope\n          over the entire \'<NN>\'; and so that in \'<NN|IN>\', the \'|\' has\n          scope over \'NN\' and \'IN\', but not \'<\' or \'>\'.\n        - Check to make sure the resulting pattern is valid.\n\n    :type tag_pattern: str\n    :param tag_pattern: The tag pattern to convert to a regular\n        expression pattern.\n    :raise ValueError: If ``tag_pattern`` is not a valid tag pattern.\n        In particular, ``tag_pattern`` should not include braces; and it\n        should not contain nested or mismatched angle-brackets.\n    :rtype: str\n    :return: A regular expression pattern corresponding to\n        ``tag_pattern``.\n    '
    tag_pattern = re.sub('\\s', '', tag_pattern)
    tag_pattern = re.sub('<', '(<(', tc_rev)
    tag_pattern = re.sub('>', ')>)', tag_pattern)
    if (not CHUNK_TAG_PATTERN.match(tag_pattern)):
        raise ValueError(('Bad tag pattern: %r' % tag_pattern))

    def reverse_str(str):
        lst = list(str)
        lst.reverse()
        return ''.join(lst)
    tc_rev = reverse_str(ChunkString.CHUNK_TAG_CHAR)
    reversed = reverse_str(tag_pattern)
    reversed = re.sub('\\.(?!\\\\(\\\\\\\\)*($|[^\\\\]))', tc_rev, reversed)
    tag_pattern = reverse_str(reversed)
    return tag_pattern

dataset/ETHPy150Open nltk/nltk/nltk/chunk/regexp.py tag_pattern2re_pattern/VarMisuse@35/725 `tag_pattern`->`tc_rev`