Files
wehub-resource-sync 3454a55636
cffconvert / validate (push) Has been cancelled
ci-workflow / pre-commit (push) Has been cancelled
ci-workflow / Minimal NLTK Download Test (macos-latest) (push) Has been cancelled
ci-workflow / Minimal NLTK Download Test (ubuntu-latest) (push) Has been cancelled
ci-workflow / Minimal NLTK Download Test (windows-latest) (push) Has been cancelled
ci-workflow / Python 3.10 on macos-latest (push) Has been cancelled
ci-workflow / Python 3.11 on macos-latest (push) Has been cancelled
ci-workflow / Python 3.12 on macos-latest (push) Has been cancelled
ci-workflow / Python 3.13 on macos-latest (push) Has been cancelled
ci-workflow / Python 3.14 on macos-latest (push) Has been cancelled
ci-workflow / Python 3.14t on macos-latest (push) Has been cancelled
ci-workflow / Python 3.10 on ubuntu-latest (push) Has been cancelled
ci-workflow / Python 3.11 on ubuntu-latest (push) Has been cancelled
ci-workflow / Python 3.12 on ubuntu-latest (push) Has been cancelled
ci-workflow / Python 3.13 on ubuntu-latest (push) Has been cancelled
ci-workflow / Python 3.14 on ubuntu-latest (push) Has been cancelled
ci-workflow / Python 3.14t on ubuntu-latest (push) Has been cancelled
ci-workflow / Python 3.10 on windows-latest (push) Has been cancelled
ci-workflow / Python 3.11 on windows-latest (push) Has been cancelled
ci-workflow / Python 3.12 on windows-latest (push) Has been cancelled
ci-workflow / Python 3.13 on windows-latest (push) Has been cancelled
ci-workflow / Python 3.14 on windows-latest (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:46:15 +08:00

86 lines
2.1 KiB
Python

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)
./.)"""
)