Skip to content

Commit 9a19801

Browse files
committed
Add doctests
1 parent c28cee7 commit 9a19801

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

nltk/test/wordnet.doctest

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Lemmas
156156
>>> wn.lemma_from_key(eat.key()).synset()
157157
Synset('feed.v.06')
158158
>>> wn.lemma_from_key('feebleminded%5:00:00:retarded:00')
159-
Lemma('backward.s.03.feebleminded')
159+
Lemma('backward.s.01.feebleminded')
160160
>>> for lemma in wn.synset('eat.v.03').lemmas():
161161
... print(lemma, lemma.count())
162162
...
@@ -397,6 +397,29 @@ Walk through the noun synsets looking at their hypernyms:
397397
Synset('object.n.01') [Synset('physical_entity.n.01')]
398398

399399

400+
# Test for PR #3400: When specifying pos="a", both head adjectives and adjective satellites are returned.
401+
402+
>>> from nltk.corpus import wordnet as wn
403+
>>> # All adjective synsets (heads and satellites) for "good"
404+
>>> syns_a = wn.synsets('good', pos='a')
405+
>>> sorted(set(s.pos() for s in syns_a))
406+
['a', 's']
407+
>>> # Only head adjectives
408+
>>> syns_head = [s for s in syns_a if s.pos() == 'a']
409+
>>> all(s.pos() == 'a' for s in syns_head)
410+
True
411+
>>> # Only satellites
412+
>>> syns_sat = wn.synsets('good', pos='s')
413+
>>> all(s.pos() == 's' for s in syns_sat)
414+
True
415+
>>> # The union when using pos='a' matches the combined sets
416+
>>> set(syns_a) == set(syns_head) | set(syns_sat)
417+
True
418+
>>> # But pos='s' never returns head adjectives
419+
>>> all(s.pos() != 'a' for s in wn.synsets('good', pos='s'))
420+
True
421+
422+
400423
------
401424
Morphy
402425
------
@@ -648,7 +671,7 @@ Issue 3077: Incorrect part-of-speech filtering in all_synsets
648671
>>> next(wn.all_synsets(lang="hrv", pos="v"))
649672
Synset('breathe.v.01')
650673
>>> next(wn.all_synsets(lang="hrv", pos="s"))
651-
Synset('ideological.s.02')
674+
Synset('ideological.s.01')
652675
>>> next(wn.all_synsets(lang="hrv", pos="a"))
653676
Synset('able.a.01')
654677

0 commit comments

Comments
 (0)