

@staticmethod
def fromstring(s):
    "\n        Create a RegexpChunkRule from a string description.\n        Currently, the following formats are supported::\n\n          {regexp}         # chunk rule\n          }regexp{         # chink rule\n          regexp}{regexp   # split rule\n          regexp{}regexp   # merge rule\n\n        Where ``regexp`` is a regular expression for the rule.  Any\n        text following the comment marker (``#``) will be used as\n        the rule's description:\n\n        >>> from nltk.chunk.regexp import RegexpChunkRule\n        >>> RegexpChunkRule.fromstring('{<DT>?<NN.*>+}')\n        <ChunkRule: '<DT>?<NN.*>+'>\n        "
    m = re.match('(?P<rule>(\\\\.|[^#])*)(?P<comment>#.*)?', s)
    rule = m.group('rule').strip()
    comment = (m.group('comment') or '')[1:].strip()
    try:
        if (not rule):
            raise ValueError('Empty chunk pattern')
        if ((rule[0] == '{') and (rule[(- 1)] == '}')):
            return ChunkRule(rule[1:(- 1)], comment)
        elif ((rule[0] == '}') and (rule[(- 1)] == '{')):
            return ChinkRule(rule[1:(- 1)], comment)
        elif ('}{' in rule):
            (left, right) = rule.split('}{')
            return SplitRule(left, right, comment)
        elif ('{}' in rule):
            (left, right) = rule.split('{}')
            return MergeRule(left, right, comment)
        elif re.match('[^{}]*{[^{}]*}[^{}]*', rule):
            (left, chunk, right) = re.split('[{}]', rule)
            return ChunkRuleWithContext(left, chunk, right, comment)
        else:
            raise ValueError(('Illegal chunk pattern: %s' % rule))
    except (ValueError, re.error):
        raise ValueError(('Illegal chunk pattern: %s' % chunk))

dataset/ETHPy150Open nltk/nltk/nltk/chunk/regexp.py RegexpChunkRule.fromstring/VarMisuse@306/598 `rule`->`chunk`