File size: 2,219 Bytes
0f7793d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import unittest

from nltk import RegexpParser


class TestChunkRule(unittest.TestCase):
    def test_tag_pattern2re_pattern_quantifier(self):
        """Test for bug https://github.com/nltk/nltk/issues/1597



        Ensures that curly bracket quantifiers can be used inside a chunk rule.

        This type of quantifier has been used for the supplementary example

        in https://www.nltk.org/book/ch07.html#exploring-text-corpora.

        """
        sent = [
            ("The", "AT"),
            ("September-October", "NP"),
            ("term", "NN"),
            ("jury", "NN"),
            ("had", "HVD"),
            ("been", "BEN"),
            ("charged", "VBN"),
            ("by", "IN"),
            ("Fulton", "NP-TL"),
            ("Superior", "JJ-TL"),
            ("Court", "NN-TL"),
            ("Judge", "NN-TL"),
            ("Durwood", "NP"),
            ("Pye", "NP"),
            ("to", "TO"),
            ("investigate", "VB"),
            ("reports", "NNS"),
            ("of", "IN"),
            ("possible", "JJ"),
            ("``", "``"),
            ("irregularities", "NNS"),
            ("''", "''"),
            ("in", "IN"),
            ("the", "AT"),
            ("hard-fought", "JJ"),
            ("primary", "NN"),
            ("which", "WDT"),
            ("was", "BEDZ"),
            ("won", "VBN"),
            ("by", "IN"),
            ("Mayor-nominate", "NN-TL"),
            ("Ivan", "NP"),
            ("Allen", "NP"),
            ("Jr.", "NP"),
            (".", "."),
        ]  # source: brown corpus
        cp = RegexpParser("CHUNK: {<N.*>{4,}}")
        tree = cp.parse(sent)
        assert (
            tree.pformat()
            == """(S

  The/AT

  September-October/NP

  term/NN

  jury/NN

  had/HVD

  been/BEN

  charged/VBN

  by/IN

  Fulton/NP-TL

  Superior/JJ-TL

  (CHUNK Court/NN-TL Judge/NN-TL Durwood/NP Pye/NP)

  to/TO

  investigate/VB

  reports/NNS

  of/IN

  possible/JJ

  ``/``

  irregularities/NNS

  ''/''

  in/IN

  the/AT

  hard-fought/JJ

  primary/NN

  which/WDT

  was/BEDZ

  won/VBN

  by/IN

  (CHUNK Mayor-nominate/NN-TL Ivan/NP Allen/NP Jr./NP)

  ./.)"""
        )