Skip to content

Commit a2cc2e9

Browse files
ekafCopilot
andauthored
Update nltk/corpus/reader/wordnet.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 8dbe9a9 commit a2cc2e9

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

nltk/corpus/reader/wordnet.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,14 +2110,23 @@ def filter_forms(forms):
21102110

21112111
def tag2pos(self, tag, tagset="en-ptb") -> Optional[str]:
21122112
"""
2113-
Convert a tag from one of the tagsets in nltk_data/taggers/universal_tagset, to a
2113+
Convert a tag from one of the tagsets in nltk_data/taggers/universal_tagset to a
21142114
WordNet Part-of-Speech, using Universal Tags (Petrov et al., 2012) as intermediary.
2115-
Return None when WordNet does not cover that Pos.
2115+
Return None when WordNet does not cover that POS.
21162116
2117-
>>> import nltk
2118-
>>> tagged = nltk.tag.pos_tag(nltk.tokenize.word_tokenize("Banks check books."))
2119-
>>> print([(word, tag, nltk.corpus.wordnet.tag2pos(tag)) for word,tag in tagged])
2120-
[('Banks', 'NNS', 'n'), ('check', 'VBP', 'v'), ('books', 'NNS', 'n'), ('.', '.', None)]
2117+
Args:
2118+
tag (str): The part-of-speech tag to convert.
2119+
tagset (str): The tagset of the input tag. Defaults to "en-ptb".
2120+
2121+
Returns:
2122+
Optional[str]: The corresponding WordNet POS tag ('n', 'v', 'a', 'r') or None
2123+
if the tag cannot be mapped to a WordNet POS.
2124+
2125+
Example:
2126+
>>> import nltk
2127+
>>> tagged = nltk.tag.pos_tag(nltk.tokenize.word_tokenize("Banks check books."))
2128+
>>> print([(word, tag, nltk.corpus.wordnet.tag2pos(tag)) for word, tag in tagged])
2129+
[('Banks', 'NNS', 'n'), ('check', 'VBP', 'v'), ('books', 'NNS', 'n'), ('.', '.', None)]
21212130
"""
21222131

21232132
from nltk.tag import map_tag

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy