Skip to content

Commit d74b29a

Browse files
committed
Improve unit tests
1 parent 5064164 commit d74b29a

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

nltk/test/unit/test_wordnet.py

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -246,19 +246,54 @@ def test_iterable_type_for_all_lemma_names(self):
246246
self.assertTrue(cat_lemmas.__iter__() is cat_lemmas)
247247

248248
def test_en_ptb_tags(self):
249-
# Penn Treebank tags
249+
# Common PTB tags (mapped in both PTB and Brown)
250250
self.assertEqual(wn.tag2pos("NN"), "n") # noun
251-
self.assertEqual(wn.tag2pos("NNS"), "n")
252251
self.assertEqual(wn.tag2pos("VB"), "v") # verb
253-
self.assertEqual(wn.tag2pos("VBD"), "v")
254252
self.assertEqual(wn.tag2pos("JJ"), "a") # adjective
255253
self.assertEqual(wn.tag2pos("RB"), "r") # adverb
256-
self.assertIsNone(wn.tag2pos(".")) # punctuation
254+
255+
def test_en_ptb_tags(self):
256+
# Common PTB tags (mapped in both PTB and Brown)
257+
self.assertEqual(wn.tag2pos("NN"), "n") # noun
258+
self.assertEqual(wn.tag2pos("VB"), "v") # verb
259+
self.assertEqual(wn.tag2pos("JJ"), "a") # adjective
260+
self.assertEqual(wn.tag2pos("RB"), "r") # adverb
261+
262+
# PTB-specific tags (mapped in PTB, not in Brown)
263+
self.assertEqual(wn.tag2pos("NNS"), "n") # plural noun (PTB only)
264+
self.assertEqual(wn.tag2pos("VBD"), "v") # verb, past tense (PTB only)
265+
self.assertEqual(
266+
wn.tag2pos("VBG"), "v"
267+
) # verb, gerund/present participle (PTB only)
268+
self.assertEqual(wn.tag2pos("JJR"), "a") # adjective, comparative (PTB only)
269+
self.assertEqual(wn.tag2pos("RBR"), "r") # adverb, comparative (PTB only)
270+
271+
# Tags that should yield None (not mapped in WordNet)
272+
self.assertIsNone(wn.tag2pos("PRP"))
273+
self.assertIsNone(wn.tag2pos("WP"))
274+
self.assertIsNone(wn.tag2pos("TO"))
275+
self.assertIsNone(wn.tag2pos("PRT"))
276+
self.assertIsNone(wn.tag2pos("POS"))
277+
self.assertIsNone(wn.tag2pos("."))
257278

258279
def test_en_brown_tags(self):
259-
# Brown tagset
260-
self.assertEqual(wn.tag2pos("NN", tagset="en-brown"), "n")
261-
self.assertEqual(wn.tag2pos("VB", tagset="en-brown"), "v")
262-
self.assertEqual(wn.tag2pos("JJ", tagset="en-brown"), "a")
263-
self.assertEqual(wn.tag2pos("RB", tagset="en-brown"), "r")
280+
# Common Brown tags (mapped in both PTB and Brown)
281+
self.assertEqual(wn.tag2pos("NN", tagset="en-brown"), "n") # noun
282+
self.assertEqual(wn.tag2pos("VB", tagset="en-brown"), "v") # verb
283+
self.assertEqual(wn.tag2pos("JJ", tagset="en-brown"), "a") # adjective
284+
self.assertEqual(wn.tag2pos("RB", tagset="en-brown"), "r") # adverb
285+
286+
# Brown-specific tags (mapped in Brown, not in PTB)
287+
self.assertEqual(
288+
wn.tag2pos("HV", tagset="en-brown"), "v"
289+
) # 'have' auxiliary (Brown only)
290+
self.assertEqual(
291+
wn.tag2pos("BEZ", tagset="en-brown"), "v"
292+
) # 'be' auxiliary, 3rd person singular present (Brown only)
293+
self.assertEqual(
294+
wn.tag2pos("DOZ", tagset="en-brown"), "v"
295+
) # 'do' auxiliary, 3rd person singular present (Brown only)
296+
297+
# Tags that should yield None (not mapped in WordNet)
298+
self.assertIsNone(wn.tag2pos("PPL", tagset="en-brown"))
264299
self.assertIsNone(wn.tag2pos("(", tagset="en-brown"))

0 commit comments

Comments
 (0)