

def demo():
    '\n    A demonstration for the ``RegexpChunkParser`` class.  A single text is\n    parsed with four different chunk parsers, using a variety of rules\n    and strategies.\n    '
    from nltk import chunk, Tree
    text = '    [ the/DT little/JJ cat/NN ] sat/VBD on/IN [ the/DT mat/NN ] ./.\n    [ John/NNP ] saw/VBD [the/DT cats/NNS] [the/DT dog/NN] chased/VBD ./.\n    [ John/NNP ] thinks/VBZ [ Mary/NN ] saw/VBD [ the/DT cat/NN ] sit/VB on/IN [ the/DT mat/NN ]./.\n    '
    print(('*' * 75))
    print('Evaluation text:')
    print(text)
    print(('*' * 75))
    print()
    grammar = '\n    NP:                   # NP stage\n      {<DT>?<JJ>*<NN>}    # chunk determiners, adjectives and nouns\n      {<NNP>+}            # chunk proper nouns\n    '
    cp = chunk.RegexpParser(grammar)
    demo_eval(cp, text)
    grammar = '\n    NP:\n      {<.*>}              # start by chunking each tag\n      }<[\\.VI].*>+{       # unchunk any verbs, prepositions or periods\n      <DT|JJ>{}<NN.*>     # merge det/adj with nouns\n    '
    cp = chunk.RegexpParser(grammar)
    demo_eval(cp, text)
    grammar = '\n    NP: {<DT>?<JJ>*<NN>}    # chunk determiners, adjectives and nouns\n    VP: {<TO>?<VB.*>}       # VP = verb words\n    '
    cp = chunk.RegexpParser(grammar)
    demo_eval(cp, text)
    grammar = '\n    NP: {<.*>*}             # start by chunking everything\n        }<[\\.VI].*>+{       # chink any verbs, prepositions or periods\n        <.*>}{<DT>          # separate on determiners\n    PP: {<IN><NP>}          # PP = preposition + noun phrase\n    VP: {<VB.*><NP|PP>*}    # VP = verb words + NPs and PPs\n    '
    cp = chunk.RegexpParser(grammar)
    demo_eval(cp, text)
    from nltk.corpus import conll2000
    print()
    print('Demonstration of empty grammar:')
    cp = chunk.RegexpParser('')
    print(chunk.accuracy(cp, conll2000.chunked_sents('test.txt', chunk_types=('NP',))))
    print()
    print('Demonstration of accuracy evaluation using CoNLL tags:')
    grammar = '\n    NP:\n      {<.*>}              # start by chunking each tag\n      }<[\\.VI].*>+{       # unchunk any verbs, prepositions or periods\n      <DT|JJ>{}<NN.*>     # merge det/adj with nouns\n    '
    cp = chunk.RegexpParser(grammar)
    print(chunk.accuracy(cp, conll2000.chunked_sents('test.txt')[:5]))
    print()
    print('Demonstration of tagged token input')
    grammar = '\n    NP: {<.*>*}             # start by chunking everything\n        }<[\\.VI].*>+{       # chink any verbs, prepositions or periods\n        <.*>}{<DT>          # separate on determiners\n    PP: {<IN><NP>}          # PP = preposition + noun phrase\n    VP: {<VB.*><NP|PP>*}    # VP = verb words + NPs and PPs\n    '
    cp = chunk.RegexpParser(grammar)
    print(cp.parse([('the', 'DT'), ('little', 'JJ'), ('cat', 'NN'), ('sat', 'VBD'), ('on', 'IN'), ('the', 'DT'), ('mat', 'NN'), ('.', '.')]))

dataset/ETHPy150Open nltk/nltk/nltk/chunk/regexp.py demo/original